Merge lp:~dreamdevel/eradio/newDatabase into lp:eradio/luna

Proposed by Fotini Skoti
Status: Merged
Merged at revision: 67
Proposed branch: lp:~dreamdevel/eradio/newDatabase
Merge into: lp:eradio/luna
Diff against target: 1262 lines (+716/-169)
13 files modified
CMakeLists.txt (+3/-1)
debian/control (+2/-1)
src/database.vala (+510/-0)
src/extract_dialog.vala (+3/-8)
src/genre.vala (+29/-0)
src/main_window.vala (+45/-24)
src/package_manager.vala (+21/-2)
src/radio.vala (+27/-1)
src/station.vala (+8/-13)
src/station_dialog.vala (+2/-1)
src/station_list.vala (+39/-101)
src/station_selection_list.vala (+19/-12)
src/stations.vala (+8/-5)
To merge this branch: bzr merge lp:~dreamdevel/eradio/newDatabase
Reviewer Review Type Date Requested Status
George Sofianos Approve
Review via email: mp+234809@code.launchpad.net

Description of the change

Implemented Blueprints
   https://blueprints.launchpad.net/eradio/+spec/new-database-structure
   https://blueprints.launchpad.net/eradio/+spec/sqlite3-to-sqlheavy

Added white space trim to dialog entries
Enabled empty genre entry

To post a comment you must log in.
lp:~dreamdevel/eradio/newDatabase updated
68. By George Sofianos

Removed some comments

Revision history for this message
George Sofianos (georgesofianosgr) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2014-07-06 09:00:32 +0000
3+++ CMakeLists.txt 2014-09-17 09:38:41 +0000
4@@ -36,6 +36,7 @@
5 json-glib-1.0
6 libsoup-2.4
7 libxml-2.0
8+ sqlheavy-0.1
9 )
10
11 pkg_check_modules(DEPS REQUIRED ${PROJECT_DEPS})
12@@ -56,7 +57,6 @@
13 src/main_window.vala
14 src/stream_player.vala
15 src/station_list.vala
16- src/stations.vala
17 src/station.vala
18 src/error.vala
19 src/station_dialog.vala
20@@ -72,6 +72,8 @@
21 src/progress_dialog.vala
22 src/pls_decoder.vala
23 src/asx_decoder.vala
24+ src/genre.vala
25+ src/database.vala
26 PACKAGES
27 ${PROJECT_DEPS}
28 )
29
30=== modified file 'debian/control'
31--- debian/control 2014-07-01 17:56:24 +0000
32+++ debian/control 2014-09-17 09:38:41 +0000
33@@ -13,7 +13,8 @@
34 libnotify-dev,
35 libjson-glib-dev,
36 libsoup2.4-dev,
37- libxml2-dev
38+ libxml2-dev,
39+ libsqlheavy0.1-dev
40 Standards-Version: 3.9.3
41
42 Package: eradio
43
44=== added file 'src/database.vala'
45--- src/database.vala 1970-01-01 00:00:00 +0000
46+++ src/database.vala 2014-09-17 09:38:41 +0000
47@@ -0,0 +1,510 @@
48+/*-
49+ * Copyright (c) 2014 Dream Dev Developers (https://launchpad.net/~dreamdev)
50+ *
51+ * This program is free software: you can redistribute it and/or modify
52+ * it under the terms of the GNU General Public License as published by
53+ * the Free Software Foundation, either version 3 of the License, or
54+ * (at your option) any later version.
55+ *
56+ * This program is distributed in the hope that it will be useful,
57+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
58+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
59+ * GNU General Public License for more details.
60+ *
61+ * You should have received a copy of the GNU General Public License
62+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
63+ *
64+ * Authored by: Fotini Skoti <fotini.skoti@gmail.com>
65+ */
66+
67+ public class Radio.Database {
68+
69+ private string database_path;
70+ private SQLHeavy.Database db;
71+
72+ public Database.with_db_file (string path) throws Radio.Error {
73+
74+ database_path = path;
75+
76+ try {
77+ db = new SQLHeavy.Database (database_path);
78+ }
79+ catch (SQLHeavy.Error e) {
80+ throw new Radio.Error.SQLITE_OPEN_DB_FAILED (
81+ "Couldn't Open Database: Error Code %d \nError Message: %s\n".printf (e.code,e.message));
82+ }
83+
84+ try {
85+ db.run ("""CREATE TABLE IF NOT EXISTS `Stations`(id INTEGER PRIMARY KEY, name TEXT, url TEXT);
86+ CREATE TABLE IF NOT EXISTS `Genres`(id INTEGER PRIMARY KEY, name TEXT);
87+ CREATE TABLE IF NOT EXISTS `StationsGenres`(station_id INTEGER, genre_id INTEGER,
88+ PRIMARY KEY(station_id,genre_id));""");
89+ }
90+ catch (SQLHeavy.Error e) {
91+ throw new Radio.Error.SQLITE_CREATE_FAILED (
92+ "Couldn't Create Tables: Error Code %d \nError Message: %s\n".printf (e.code,e.message));
93+ }
94+ }
95+
96+ public void new_station (string name, Gee.ArrayList <string> genres, string url) {
97+ int flag = 0;
98+
99+ try {
100+ add_station (name, url);
101+ int? station_id = null;
102+
103+ try {
104+ SQLHeavy.QueryResult results = db.execute ("SELECT * FROM Stations ORDER BY id DESC LIMIT 1");
105+
106+ if (!results.finished){
107+ station_id = (int) results.get ("id").get_int64 ();
108+ }
109+ }
110+ catch (SQLHeavy.Error e) {
111+ throw new Radio.Error.SQLITE_SELECT_FAILED (
112+ "Couldn't Select Entry: Error Code %d \nError Message: %s\n".printf (e.code,e.message));
113+ }
114+
115+ if (station_id != null) {
116+ foreach (string genre_name in genres) {
117+
118+ if (get_genre_by_name (genre_name) == null) {
119+ add_genre (genre_name);
120+ var genre_id = get_genre_by_name (genre_name).id;
121+ link_genre (station_id, genre_id);
122+ }
123+ else {
124+
125+ var linked_genres = get_linked_genres (station_id);
126+ foreach ( string genre in linked_genres){
127+ if (genre == genre_name){
128+ flag = 1;
129+ break;
130+ }
131+ }
132+
133+ if (flag == 0) {
134+ var genre_id = get_genre_by_name (genre_name).id;
135+ link_genre (station_id, genre_id);
136+ }
137+ }
138+ }
139+ }
140+ }
141+ catch (Radio.Error e) {
142+ stderr.printf (e.message);
143+ }
144+
145+ }
146+
147+ public void update_station_details (int id, string name, Gee.ArrayList<string> genres, string url) {
148+
149+ int flag;
150+
151+ try {
152+ if (get_station_by_id (id) != null) {
153+
154+ update_station (id, name, url);
155+ var existing_genres = get_linked_genres (id);
156+
157+ foreach (string new_genre in genres) {
158+
159+ flag = 0;
160+ foreach (string old_genre in existing_genres) {
161+
162+ if (new_genre == old_genre){
163+ flag = 1;
164+ break;
165+ }
166+ }
167+
168+ if (flag == 0) {
169+ add_genre (new_genre);
170+ link_genre (id, get_genre_by_name (new_genre).id);
171+ }
172+ }
173+
174+ foreach (string old_genre in existing_genres) {
175+ flag = 0;
176+
177+ foreach (string new_genre in genres) {
178+ if (new_genre == old_genre){
179+
180+ flag = 1;
181+ break;
182+ }
183+ }
184+
185+ if (flag == 0) {
186+ var genre = get_genre_by_name (old_genre);
187+ unlink_genre (id, genre.id);
188+ if (count_genre_entries_by_id (genre.id) == 0)
189+ delete_genre (genre.id);
190+ }
191+ }
192+ }
193+ }
194+ catch (Radio.Error e) {
195+ stderr.printf (e.message);
196+ }
197+ }
198+
199+ public void remove_station (int id) {
200+ try {
201+ if (get_station_by_id (id) != null) {
202+
203+ var genres = get_linked_genres (id);
204+
205+ foreach (string genre in genres) {
206+ var genre_id = get_genre_by_name (genre).id;
207+ unlink_genre (id, genre_id);
208+
209+ if (count_genre_entries_by_id (genre_id) == 0)
210+ delete_genre (genre_id);
211+ }
212+ delete_station (id);
213+ }
214+ }
215+ catch (Radio.Error e) {
216+ stderr.printf (e.message);
217+ }
218+ }
219+
220+ public Gee.ArrayList<Radio.Station>? get_all_stations () {
221+
222+ var stations_list = new Gee.ArrayList<Radio.Station> ();
223+
224+ try {
225+ SQLHeavy.Query query = db.prepare ("SELECT * FROM `Stations`;");
226+
227+ for (SQLHeavy.QueryResult results = query.execute (); !results.finished; results.next ()) {
228+
229+ string name = results.get ("name").get_string ();
230+ string url = results.get ("url").get_string ();
231+ int id = (int) results.get ("id").get_int64 ();
232+
233+ try {
234+ var genres = get_linked_genres (id);
235+ var station = new Radio.Station (id, name, url, genres);
236+ stations_list.add (station);
237+ }
238+ catch (Radio.Error e) {
239+ stderr.printf (e.message);
240+ return null;
241+ }
242+ }
243+ return stations_list;
244+ }
245+ catch (SQLHeavy.Error e) {
246+ stderr.printf (e.message);
247+ }
248+
249+ return null;
250+ }
251+
252+ public Gee.ArrayList<Radio.Station> get_stations_by_genre (int id) {
253+
254+ var stations_list = new Gee.ArrayList<Radio.Station> ();
255+
256+ try {
257+ SQLHeavy.Query query = db.prepare ("""SELECT Stations.* FROM Stations, StationsGenres
258+ WHERE Stations.id = StationsGenres.station_id AND StationsGenres.genre_id = :id;""");
259+ query.set_int (":id",id);
260+
261+ for (SQLHeavy.QueryResult results = query.execute (); !results.finished; results.next ()) {
262+
263+ string station_name = results.get ("name").get_string ();
264+ string station_url = results.get ("url").get_string ();
265+ int station_id = (int) results.get ("id").get_int64 ();
266+
267+ try {
268+ var genres = get_linked_genres (station_id);
269+ var station = new Radio.Station (station_id, station_name, station_url, genres);
270+ stations_list.add (station);
271+ }
272+ catch (Radio.Error e) {
273+ stderr.printf (e.message);
274+ }
275+ }
276+ }
277+ catch (SQLHeavy.Error e) {
278+ stderr.printf (e.message);
279+ }
280+ return stations_list;
281+ }
282+
283+ public Gee.ArrayList<Radio.Genre>? get_all_genres () {
284+
285+ var genres_list = new Gee.ArrayList<Radio.Genre> ();
286+
287+ try {
288+ SQLHeavy.Query query = db.prepare ("SELECT * FROM `Genres`;");
289+
290+ for (SQLHeavy.QueryResult results = query.execute (); !results.finished; results.next ()) {
291+ string name = results.get ("name").get_string ();
292+ int id = (int) results.get ("id").get_int64 ();
293+
294+ var genre = new Radio.Genre (id, name);
295+ genres_list.add (genre);
296+ }
297+ }
298+ catch (SQLHeavy.Error e) {
299+ stderr.printf(e.message);
300+ }
301+
302+ if (genres_list.size == 0)
303+ return null;
304+ return genres_list;
305+ }
306+
307+ public Radio.Genre? get_genre_by_id (int id) {
308+
309+ try {
310+ SQLHeavy.Query query = db.prepare ("SELECT * FROM `Genres` WHERE `id` = :id;");
311+ query.set_int (":id", id);
312+
313+ SQLHeavy.QueryResult results = query.execute ();
314+ if (!results.finished) {
315+
316+ string genre_name = results.get ("name").get_string ();
317+ int genre_id = (int) results.get ("id").get_int64 ();
318+
319+ var genre = new Radio.Genre (genre_id, genre_name);
320+ return genre;
321+ }
322+ }
323+ catch (SQLHeavy.Error e) {
324+ stderr.printf (e.message);
325+ }
326+ return null;
327+ }
328+
329+ public Radio.Station? get_station_by_id (int id) {
330+
331+ try {
332+ SQLHeavy.Query query = db.prepare ("SELECT * FROM `Stations` WHERE `id` = :id;");
333+ query.set_int (":id", id);
334+
335+ SQLHeavy.QueryResult results = query.execute ();
336+ if (!results.finished) {
337+
338+ string station_name = results.get ("name").get_string ();
339+ string station_url = results.get ("url").get_string ();
340+
341+ try {
342+ var genres = get_linked_genres (id);
343+ var station = new Radio.Station (id, station_name, station_url, genres);
344+ return station;
345+ }
346+ catch (Radio.Error e) {
347+ stderr.printf (e.message);
348+ }
349+ }
350+ }
351+ catch (SQLHeavy.Error e) {
352+ stderr.printf (e.message);
353+ }
354+ return null;
355+ }
356+
357+ public int? count_genre_entries_by_id (int id) {
358+ try{
359+ SQLHeavy.Query query = db.prepare ("SELECT COUNT(genre_id) FROM StationsGenres WHERE genre_id = :id;");
360+ query.set_int (":id",id);
361+
362+ SQLHeavy.QueryResult results = query.execute ();
363+ if (!results.finished) {
364+ return results.fetch_int (0);
365+ }
366+ }
367+ catch (SQLHeavy.Error e) {
368+ stderr.printf (e.message);
369+ }
370+ return null;
371+ }
372+
373+ public int count_stations () {
374+
375+ var num_stations = 0;
376+ try {
377+ SQLHeavy.QueryResult results = db.execute ("SELECT COUNT(id) FROM Stations");
378+ if (!results.finished) {
379+ num_stations = results.fetch_int (0);
380+ }
381+ }
382+ catch (SQLHeavy.Error e) {
383+ stderr.printf (e.message);
384+ }
385+ return num_stations;
386+ }
387+
388+ private Radio.Station? get_station_by_name (string name) throws Radio.Error {
389+
390+ try {
391+ SQLHeavy.Query query = db.prepare ("SELECT * FROM `Stations` WHERE `name` = :name;");
392+ query.set_string (":name", name);
393+ SQLHeavy.QueryResult results = query.execute ();
394+
395+ if (!results.finished) {
396+ var station_id = (int) results.get ("id").get_int64 ();
397+ var station_name = results.get ("name").get_string ();
398+ var station_url = results.get ("url").get_string ();
399+
400+ try {
401+ var station_genres = get_linked_genres (station_id);
402+ var station = new Radio.Station (station_id, station_name, station_url, station_genres);
403+ return station;
404+ }
405+ catch (Radio.Error e) {
406+ stderr.printf (e.message);
407+ }
408+ }
409+ }
410+ catch (SQLHeavy.Error e){
411+ throw new Radio.Error.SQLITE_SELECT_FAILED (
412+ "Couldn't Select Entry: Error Code %d \nError Message: %s\n".printf (e.code,e.message));
413+ }
414+ return null;
415+ }
416+
417+ private Radio.Genre? get_genre_by_name (string name) throws Radio.Error {
418+
419+ try {
420+ SQLHeavy.Query query = db.prepare ("SELECT * FROM `Genres` WHERE `name` = :name;");
421+ query.set_string (":name", name);
422+ SQLHeavy.QueryResult results = query.execute ();
423+
424+ if (!results.finished) {
425+ var id = (int) results.get ("id").get_int64 ();
426+ var genre = new Radio.Genre (id,name);
427+ return genre;
428+ }
429+ }
430+ catch (SQLHeavy.Error e){
431+ throw new Radio.Error.SQLITE_SELECT_FAILED (
432+ "Couldn't Select Entry: Error Code %d \nError Message: %s\n".printf (e.code,e.message));
433+ }
434+ return null;
435+ }
436+
437+ //return genres which are linked to given station
438+ private Gee.ArrayList<string> get_linked_genres (int id) throws Radio.Error {
439+
440+ var genres_name = new Gee.ArrayList<string> ();
441+
442+ try{
443+ SQLHeavy.Query query = db.prepare ("""SELECT Genres.name FROM Genres,StationsGenres WHERE StationsGenres.genre_id = Genres.id
444+ AND StationsGenres.station_id = :id;""");
445+ query.set_int (":id",id);
446+
447+ for (SQLHeavy.QueryResult results = query.execute (); !results.finished; results.next ()) {
448+ genres_name.add (results.get ("name").get_string ());
449+ }
450+ }
451+ catch (SQLHeavy.Error e) {
452+ throw new Radio.Error.SQLITE_SELECT_FAILED (
453+ "Couldn't Select Entry: Error Code %d \nError Message: %s\n".printf (e.code,e.message));
454+ }
455+
456+ return genres_name;
457+ }
458+
459+ private void add_station (string name, string url) throws Radio.Error {
460+
461+ try {
462+ SQLHeavy.Query query = db.prepare ("INSERT INTO `Stations` VALUES (null, :name, :url);");
463+
464+ query.set_string (":name", name);
465+ query.set_string (":url", url);
466+ query.execute ();
467+ }
468+ catch (SQLHeavy.Error e) {
469+ throw new Radio.Error.SQLITE_INSERT_FAILED (
470+ "Couldn't Insert Entry: Error Code %d \nError Message: %s\n".printf (e.code,e.message));
471+ }
472+ }
473+
474+ private void add_genre (string name) throws Radio.Error {
475+
476+ try {
477+ SQLHeavy.Query query = db.prepare ("INSERT INTO `Genres` VALUES (null, :name);");
478+ query.set_string (":name", name);
479+ query.execute ();
480+ }
481+ catch (SQLHeavy.Error e) {
482+ throw new Radio.Error.SQLITE_INSERT_FAILED (
483+ "Couldn't Insert Entry: Error Code %d \nError Message: %s\n".printf (e.code,e.message));
484+ }
485+ }
486+
487+ private void link_genre (int station_id, int genre_id) throws Radio.Error{
488+
489+ try {
490+ SQLHeavy.Query query = db.prepare ("INSERT INTO `StationsGenres` VALUES (:station_id, :genre_id);");
491+
492+ query.set_int (":station_id", station_id);
493+ query.set_int (":genre_id", genre_id);
494+ query.execute ();
495+ }
496+ catch (SQLHeavy.Error e) {
497+ throw new Radio.Error.SQLITE_INSERT_FAILED (
498+ "Couldn't Insert Entry: Error Code %d \nError Message: %s\n".printf (e.code,e.message));
499+ }
500+ }
501+
502+ private void unlink_genre (int station_id, int genre_id) throws Radio.Error {
503+
504+ try {
505+ SQLHeavy.Query query = db.prepare ("DELETE FROM StationsGenres WHERE station_id = :station_id AND genre_id = :genre_id;");
506+
507+ query.set_int (":station_id", station_id);
508+ query.set_int (":genre_id", genre_id);
509+ query.execute ();
510+ }
511+ catch (SQLHeavy.Error e) {
512+ throw new Radio.Error.SQLITE_DELETE_FAILED (
513+ "Couldn't Delete Entry: Error Code %d \nError Message: %s\n".printf (e.code,e.message));
514+ }
515+ }
516+
517+ private void update_station (int id, string name, string url) throws Radio.Error {
518+
519+ try {
520+ SQLHeavy.Query query = db.prepare ("UPDATE `Stations` SET `name` = :name, `url` = :url WHERE `id` = :id;");
521+ query.set_string (":name", name);
522+ query.set_string (":url", url);
523+ query.set_int (":id", id);
524+ query.execute ();
525+ }
526+ catch (SQLHeavy.Error e) {
527+ throw new Radio.Error.SQLITE_UPDATE_FAILED (
528+ "Couldn't Update Entry: Error Code %d \nError Message: %s\n".printf (e.code,e.message));
529+ }
530+ }
531+
532+ private void delete_station (int id) throws Radio.Error {
533+
534+ try {
535+ SQLHeavy.Query query = db.prepare ("DELETE FROM `Stations` WHERE `id` = :id;");
536+ query.set_int (":id", id);
537+ query.execute ();
538+ }
539+ catch (SQLHeavy.Error e) {
540+ throw new Radio.Error.SQLITE_DELETE_FAILED (
541+ "Couldn't Delete Entry: Error Code %d \nError Message: %s\n".printf (e.code,e.message));
542+ }
543+ }
544+
545+ private void delete_genre (int id) throws Radio.Error {
546+
547+ try {
548+ SQLHeavy.Query query = db.prepare ("DELETE FROM `Genres` WHERE `id` = :id;");
549+ query.set_int (":id", id);
550+ query.execute ();
551+ }
552+ catch (SQLHeavy.Error e) {
553+ throw new Radio.Error.SQLITE_DELETE_FAILED (
554+ "Couldn't Delete Entry: Error Code %d \nError Message: %s\n".printf (e.code,e.message));
555+ }
556+ }
557+}
558\ No newline at end of file
559
560=== modified file 'src/extract_dialog.vala'
561--- src/extract_dialog.vala 2014-07-01 07:49:55 +0000
562+++ src/extract_dialog.vala 2014-09-17 09:38:41 +0000
563@@ -15,6 +15,7 @@
564 * along with this program. If not, see <http://www.gnu.org/licenses/>.
565 *
566 * Authored by: George Sofianos <georgesofianosgr@gmail.com>
567+ * Fotini Skoti <fotini.skoti@gmail.com>
568 */
569
570 public class Radio.ExtractDialog : Gtk.Dialog {
571@@ -100,14 +101,8 @@
572
573 // Update list
574 this.list.clear ();
575- try {
576- var stations = Radio.App.database.get_all ();
577-
578- this.list.add_stations (stations);
579-
580- } catch (Radio.Error error) {
581- stderr.printf(error.message);
582- }
583+ var stations = Radio.App.database.get_all_stations ();
584+ this.list.add_stations (stations);
585
586 base.show ();
587 }
588
589=== added file 'src/genre.vala'
590--- src/genre.vala 1970-01-01 00:00:00 +0000
591+++ src/genre.vala 2014-09-17 09:38:41 +0000
592@@ -0,0 +1,29 @@
593+/*-
594+ * Copyright (c) 2014 Dream Dev Developers (https://launchpad.net/~dreamdev)
595+ *
596+ * This program is free software: you can redistribute it and/or modify
597+ * it under the terms of the GNU General Public License as published by
598+ * the Free Software Foundation, either version 3 of the License, or
599+ * (at your option) any later version.
600+ *
601+ * This program is distributed in the hope that it will be useful,
602+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
603+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
604+ * GNU General Public License for more details.
605+ *
606+ * You should have received a copy of the GNU General Public License
607+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
608+ *
609+ * Authored by: Fotini Skoti <fotini.skoti@gmail.com>
610+ */
611+
612+ public class Radio.Genre {
613+
614+ public int id {get;set;}
615+ public string name {get;set;}
616+
617+ public Genre (int id,string name) {
618+ this.id = id;
619+ this.name = name;
620+ }
621+}
622\ No newline at end of file
623
624=== modified file 'src/main_window.vala'
625--- src/main_window.vala 2014-07-04 07:04:50 +0000
626+++ src/main_window.vala 2014-09-17 09:38:41 +0000
627@@ -15,6 +15,7 @@
628 * along with this program. If not, see <http://www.gnu.org/licenses/>.
629 *
630 * Authored by: George Sofianos <georgesofianosgr@gmail.com>
631+ * Fotini Skoti <fotini.skoti@gmail.com>
632 */
633
634 public class Radio.MainWindow : Gtk.Window {
635@@ -76,9 +77,6 @@
636 // Set Default view
637 this.change_view(this.view_index);
638 this.stop ();
639-
640- // Temporary workout, until move database out of TreeView
641- Radio.App.database = this.list_view.stations_db;
642 }
643
644 /* --------------- Build UI ---------------- */
645@@ -155,7 +153,7 @@
646 }
647
648 // In case db has stations show list else welcome view
649- if(list_view.count () > 0 )
650+ if(Radio.App.database.count_stations () > 0 )
651 this.view_index = 1;
652
653 scroll_view = new Gtk.ScrolledWindow (null, null);
654@@ -379,37 +377,60 @@
655
656 private void dialog_add_success () {
657
658- list_view.add (dialog_add.entry_name.text,
659- dialog_add.entry_url.text,
660- dialog_add.entry_genre.text);
661-
662- if(view_index == 0 && list_view.count () > 0)
663+ string genres_text = dialog_add.entry_genre.text;
664+ string[] genres = genres_text.split (",");
665+ var genres_list = new Gee.ArrayList <string> ();
666+
667+ foreach (string iter in genres) {
668+ iter = iter.strip ();
669+ if (iter != "")
670+ genres_list.add (iter);
671+ }
672+
673+ list_view.add (dialog_add.entry_name.text.strip (),
674+ genres_list,
675+ dialog_add.entry_url.text.strip ());
676+
677+ if(view_index == 0 && Radio.App.database.count_stations () > 0)
678 change_view(1);
679 }
680
681 private void dialog_edit_open (int station_id) {
682
683- try {
684- var station = list_view.get_station(station_id);
685+ var station = Radio.App.database.get_station_by_id (station_id);
686+
687+ string genre_text = "";
688+ int arraylist_size = station.genres.size;
689+
690+ //Create a string with genre names
691+ for (int i=0; i<arraylist_size; i++) {
692+ genre_text = genre_text+station.genres[i];
693+ if (i != arraylist_size - 1)
694+ genre_text = genre_text + ", ";
695+ }
696+
697 dialog_edit.entry_name.set_text(station.name);
698- dialog_edit.entry_genre.text = station.genre;
699+ dialog_edit.entry_genre.text = genre_text;
700 dialog_edit.entry_url.text = station.url;
701 dialog_edit.show(false);
702-
703- } catch (Radio.Error error) {
704- stderr.printf(error.message);
705- var application = (Radio.App) GLib.Application.get_default();
706- application.quit();
707- }
708 }
709
710 private void dialog_edit_success () {
711
712+ string genres_text = dialog_edit.entry_genre.text;
713+ string[] genres = genres_text.split (",");
714+ var genres_list = new Gee.ArrayList <string> ();
715+
716+ foreach (string iter in genres) {
717+ iter = iter.strip ();
718+ if (iter != "")
719+ genres_list.add (iter.strip ());
720+ }
721+
722 var station = new Radio.Station (list_view.context_menu_row_id,
723- dialog_edit.entry_name.text,
724- dialog_edit.entry_url.text,
725- dialog_edit.entry_genre.text);
726-
727+ dialog_edit.entry_name.text.strip (),
728+ dialog_edit.entry_url.text.strip (),
729+ genres_list);
730 list_view.update(station);
731
732 // If currently playing change && url changed , update playback
733@@ -443,7 +464,7 @@
734 var stations = Radio.PackageManager.parse(file_chooser_import.get_filename ());
735 list_view.add_array (stations);
736
737- if(view_index == 0 && list_view.count () > 0)
738+ if(view_index == 0 && Radio.App.database.count_stations () > 0)
739 change_view(1);
740
741 } catch (Radio.Error error) {
742@@ -484,7 +505,7 @@
743
744 private void station_deleted (int station_id) {
745
746- if(view_index == 1 && list_view.count () == 0)
747+ if(view_index == 1 && Radio.App.database.count_stations () == 0)
748 change_view(0);
749
750 // Stop playback
751
752=== modified file 'src/package_manager.vala'
753--- src/package_manager.vala 2014-06-26 18:13:45 +0000
754+++ src/package_manager.vala 2014-09-17 09:38:41 +0000
755@@ -15,6 +15,7 @@
756 * along with this program. If not, see <http://www.gnu.org/licenses/>.
757 *
758 * Authored by: George Sofianos <georgesofianosgr@gmail.com>
759+ * Fotini Skoti <fotini.skoti@gmail.com>
760 */
761
762 public class Radio.PackageManager : GLib.Object {
763@@ -57,7 +58,16 @@
764 var name = station_object.get_string_member ("Name");
765 var genre = station_object.get_string_member ("Genre");
766 var url = station_object.get_string_member ("Url");
767- var station = new Radio.Station (-1,name,url,genre);
768+
769+ string[] strs = genre.split (",");
770+ var genres = new Gee.ArrayList<string> ();
771+
772+ foreach (string str in strs) {
773+
774+ genres.add (str.strip());
775+ }
776+
777+ var station = new Radio.Station (-1,name,url,genres);
778
779 stations_array[i] = station;
780 }
781@@ -85,10 +95,19 @@
782 foreach (Radio.Station station in stations) {
783 builder.begin_object ();
784
785+ string genre = "";
786+ var arraylist_size = station.genres.size;
787+
788+ for (int i=0; i<arraylist_size; i++) {
789+ genre = genre + station.genres[i];
790+ if (i != arraylist_size - 1)
791+ genre = genre + ", ";
792+ }
793+
794 builder.set_member_name ("Name");
795 builder.add_string_value (station.name);
796 builder.set_member_name ("Genre");
797- builder.add_string_value (station.genre);
798+ builder.add_string_value (genre);
799 builder.set_member_name ("Url");
800 builder.add_string_value (station.url);
801
802
803=== modified file 'src/radio.vala'
804--- src/radio.vala 2014-06-29 13:47:05 +0000
805+++ src/radio.vala 2014-09-17 09:38:41 +0000
806@@ -15,6 +15,7 @@
807 * along with this program. If not, see <http://www.gnu.org/licenses/>.
808 *
809 * Authored by: George Sofianos <georgesofianosgr@gmail.com>
810+ * Fotini Skoti <fotini.skoti@gmail.com>
811 */
812
813 class Radio.App : Granite.Application {
814@@ -31,7 +32,8 @@
815 public static Radio.StreamPlayer player;
816 public static Radio.Settings settings;
817 public static Radio.App instance;
818- public static Radio.Stations database;
819+ public static Radio.Database database;
820+
821 public static Radio.ProgressDialog progress_dialog;
822
823 public static Radio.PlaybackStatus playback_status {get;set;default=Radio.PlaybackStatus.STOPPED;}
824@@ -71,6 +73,7 @@
825 playing_station = null;
826
827 Notify.init (this.program_name);
828+ init_db ();
829 }
830
831 public App () {
832@@ -79,6 +82,29 @@
833
834 }
835
836+ private void init_db () {
837+
838+ var home_dir = File.new_for_path (Environment.get_home_dir ());
839+ var radio_dir = home_dir.get_child(".local").get_child("share").get_child("eradio");
840+ var db_file = radio_dir.get_child("stationsv2.db");
841+
842+ // Create ~/.local/share/eradio path
843+ if (! radio_dir.query_exists ()) {
844+ try {
845+ radio_dir.make_directory_with_parents();
846+ } catch (GLib.Error error) {
847+ stderr.printf(error.message);
848+ }
849+
850+ }
851+
852+ try {
853+ database = new Radio.Database.with_db_file (db_file.get_path());
854+ } catch (Radio.Error e) {
855+ stderr.printf(e.message);
856+ }
857+ }
858+
859 public override void activate () {
860 if (main_window == null) {
861 Radio.MediaKeyListener.instance.init ();
862
863=== modified file 'src/station.vala'
864--- src/station.vala 2014-06-13 08:26:44 +0000
865+++ src/station.vala 2014-09-17 09:38:41 +0000
866@@ -1,5 +1,5 @@
867 /*-
868- * Copyright (c) 2014 George Sofianos
869+ * Copyright (c) 2014 Dream Dev Developers (https://launchpad.net/~dreamdev)
870 *
871 * This program is free software: you can redistribute it and/or modify
872 * it under the terms of the GNU General Public License as published by
873@@ -15,25 +15,20 @@
874 * along with this program. If not, see <http://www.gnu.org/licenses/>.
875 *
876 * Authored by: George Sofianos <georgesofianosgr@gmail.com>
877+ * Fotini Skoti <fotini.skoti@gmail.com>
878 */
879
880-public class Radio.Station {
881+ public class Radio.Station {
882
883 public int id {get;set;}
884 public string name {get;set;}
885 public string url {get;set;}
886- public string genre {get;set;}
887+ public Gee.ArrayList<string> genres {get;set;}
888
889- public Station(int id,string name,string url,string genre) {
890+ public Station (int id, string name, string url, Gee.ArrayList<string> genres) {
891 this.id = id;
892 this.name = name;
893 this.url = url;
894- this.genre = genre;
895- }
896-
897- public string to_string(){
898-
899- return @"$id | $name | $genre | $url \n";
900- }
901-}
902-
903+ this.genres = genres;
904+ }
905+}
906\ No newline at end of file
907
908=== modified file 'src/station_dialog.vala'
909--- src/station_dialog.vala 2014-06-25 07:50:38 +0000
910+++ src/station_dialog.vala 2014-09-17 09:38:41 +0000
911@@ -15,6 +15,7 @@
912 * along with this program. If not, see <http://www.gnu.org/licenses/>.
913 *
914 * Authored by: George Sofianos <georgesofianosgr@gmail.com>
915+ * Fotini Skoti <fotini.skoti@gmail.com>
916 */
917
918 public class Radio.StationDialog : Gtk.Dialog {
919@@ -110,7 +111,7 @@
920
921 private void control_button2_sensitivity () {
922
923- if (entry_name.text.length > 0 && entry_genre.text.length > 0 && entry_url.text.length > 0 ) {
924+ if (entry_name.text.length > 0 && entry_url.text.length > 0 ) {
925 button2.set_sensitive (true);
926 }
927 else
928
929=== modified file 'src/station_list.vala'
930--- src/station_list.vala 2014-06-28 17:13:21 +0000
931+++ src/station_list.vala 2014-09-17 09:38:41 +0000
932@@ -15,12 +15,12 @@
933 * along with this program. If not, see <http://www.gnu.org/licenses/>.
934 *
935 * Authored by: George Sofianos <georgesofianosgr@gmail.com>
936+ * Fotini Skoti <fotini.skoti@gmail.com>
937 */
938
939 public class Radio.StationList : Gtk.TreeView {
940
941 private Gtk.ListStore list_source;
942- public Radio.Stations stations_db;
943
944 private Gtk.Menu context_menu;
945 private Gtk.MenuItem menu_item_edit;
946@@ -44,7 +44,6 @@
947 public StationList () throws Radio.Error {
948
949 this.build_ui ();
950- this.init_db ();
951 this.connect_signals ();
952 this.reload_list ();
953 }
954@@ -102,29 +101,6 @@
955 this.context_menu.show_all ();
956 }
957
958- private void init_db () throws Radio.Error{
959-
960- var home_dir = File.new_for_path (Environment.get_home_dir ());
961- var radio_dir = home_dir.get_child(".local").get_child("share").get_child("eradio");
962- var db_file = radio_dir.get_child("stations.db");
963-
964- // Create ~/.local/share/eradio path
965- if (! radio_dir.query_exists ()) {
966- try {
967- radio_dir.make_directory_with_parents();
968- } catch (GLib.Error error) {
969- stderr.printf(error.message);
970- }
971-
972- }
973-
974- try {
975- this.stations_db = new Radio.Stations.with_db_file (db_file.get_path());
976- } catch (Radio.Error e) {
977- this.database_error(e);
978- }
979- }
980-
981 private void connect_signals () {
982
983 this.menu_item_edit.activate.connect(this.edit_clicked);
984@@ -136,71 +112,32 @@
985
986 /* -------------- Stations Operations ---------- */
987
988- public Radio.Station get_station (int station_id) throws Radio.Error {
989- var filters = new Gee.HashMap<string,string> ();
990- filters["id"] = @"$station_id";
991- try {
992- var station = stations_db.get (filters);
993- return station[0];
994- } catch (Radio.Error error) {
995- throw error;
996- }
997- }
998+ public new void add (string name, Gee.ArrayList <string> genres, string url) {
999
1000- public new void add (string name,string url,string genre) {
1001- try {
1002- stations_db.add (name,url,genre);
1003- this.reload_list ();
1004- } catch (Radio.Error error) {
1005- stderr.printf (error.message);
1006- }
1007+ Radio.App.database.new_station (name, genres, url);
1008+ this.reload_list ();
1009 }
1010
1011 public void add_array (Radio.Station[] stations) {
1012
1013 foreach (Radio.Station station in stations) {
1014-
1015- try {
1016- stations_db.add (station.name,station.url,station.genre);
1017- } catch (Radio.Error error) {
1018- stderr.printf (error.message);
1019- }
1020+ Radio.App.database.new_station (station.name, station.genres, station.url);
1021 }
1022
1023 this.reload_list ();
1024 }
1025
1026 public void update (Radio.Station station) {
1027- try {
1028- stations_db.update (station);
1029- this.reload_list ();
1030- } catch (Radio.Error error) {
1031- stderr.printf (error.message);
1032- }
1033+
1034+ Radio.App.database.update_station_details (station.id, station.name, station.genres, station.url);
1035+ this.reload_list ();
1036 }
1037
1038 public void delete (int station_id) {
1039
1040- try {
1041- stations_db.delete (station_id);
1042- this.delete_station (station_id);
1043- this.reload_list ();
1044- } catch (Radio.Error error) {
1045- stderr.printf(error.message);
1046- }
1047-
1048- }
1049-
1050- public int count () {
1051-
1052- var num_stations = 0;
1053- try {
1054- num_stations = stations_db.count ();
1055- } catch (Radio.Error e) {
1056- stderr.printf (e.message);
1057- }
1058-
1059- return num_stations;
1060+ Radio.App.database.remove_station (station_id);
1061+ this.reload_list ();
1062+ this.delete_station (station_id);
1063 }
1064
1065
1066@@ -214,33 +151,22 @@
1067
1068 var tree_selection = this.get_selection();
1069
1070- if(tree_selection == null) {
1071+ if (tree_selection == null) {
1072 stderr.printf("Could not get TreeSelection");
1073- } else {
1074+ }
1075+ else {
1076 // Get selection id
1077 GLib.Value val;
1078 tree_selection.get_selected(out model,out iter);
1079 model.get_value(iter,3,out val);
1080
1081 // Get station object
1082- var filters = new Gee.HashMap<string,string>();
1083- filters["id"] = "%d".printf(val.get_int());
1084- Gee.ArrayList<Radio.Station> station_list;
1085-
1086- try {
1087- station_list = stations_db.get(filters);
1088-
1089- if (station_list.size == 1) {
1090- Station station = station_list[0];
1091- this.activated (station);
1092- }
1093- else {
1094- throw new Radio.Error.GENERAL (
1095- "Model returned more or less values than one - Possible Duplicate Entry or wrong entry request");
1096- }
1097- } catch (Radio.Error e) {
1098- stderr.printf(e.message);
1099- }
1100+ var station = Radio.App.database.get_station_by_id (val.get_int ());
1101+
1102+ if (station != null)
1103+ this.activated (station);
1104+ else
1105+ stderr.printf ("Model returned more or less values than one - Possible Duplicate Entry or wrong entry request");
1106 }
1107 }
1108
1109@@ -328,6 +254,7 @@
1110 }
1111
1112 private void reload_list () {
1113+
1114 // Save Station ID Before Clear List
1115 int station_id_icon = -1;
1116 if (this.iter_play_icon != null) {
1117@@ -337,25 +264,36 @@
1118 }
1119 this.clear_list ();
1120
1121- Gee.ArrayList<Radio.Station> stations;
1122- try {
1123- stations = stations_db.get_all ();
1124+ Gee.ArrayList<Radio.Station>? stations;
1125+ stations = Radio.App.database.get_all_stations ();
1126
1127+ if (stations != null) {
1128 foreach (Radio.Station station in stations) {
1129 this.add_row (station);
1130 }
1131 this.set_play_icon (station_id_icon);
1132-
1133- } catch (Radio.Error e) {
1134- stderr.printf(e.message);
1135 }
1136 }
1137
1138 private void add_row (Radio.Station station) {
1139+
1140+ string genre_text = "";
1141+ int arraylist_size = station.genres.size;
1142+
1143+ for (int i=0; i<arraylist_size; i++) {
1144+ genre_text = genre_text+station.genres [i];
1145+ if (i != arraylist_size - 1)
1146+ genre_text = genre_text + ", ";
1147+ }
1148+
1149 Gtk.TreeIter iter;
1150 list_source.append(out iter);
1151 list_source.set_value(iter,0,station.name);
1152- list_source.set_value(iter,1,station.genre);
1153+ //For empty genre display unknown
1154+ if (genre_text != "")
1155+ list_source.set_value(iter,1,genre_text);
1156+ else
1157+ list_source.set_value(iter,1,"Unknown");
1158 list_source.set_value(iter,2,station.url);
1159 list_source.set_value(iter,3,station.id);
1160 }
1161
1162=== modified file 'src/station_selection_list.vala'
1163--- src/station_selection_list.vala 2014-06-26 18:13:45 +0000
1164+++ src/station_selection_list.vala 2014-09-17 09:38:41 +0000
1165@@ -15,6 +15,7 @@
1166 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1167 *
1168 * Authored by: George Sofianos <georgesofianosgr@gmail.com>
1169+ * Fotini Skoti <fotini.skoti@gmail.com>
1170 */
1171
1172 public class Radio.StationSelectionList : Gtk.TreeView {
1173@@ -91,17 +92,10 @@
1174
1175 // Get stations from database
1176 foreach (int id in selected_stations_ids) {
1177- var filter = new Gee.HashMap<string,string> ();
1178- filter["id"] = @"$id";
1179- try {
1180- var result = Radio.App.database.get (filter);
1181- if (result.size == 1) {
1182- selected_stations.add (result.get (0) );
1183- }
1184- } catch (Radio.Error error) {
1185- stderr.printf(error.message);
1186- return null;
1187- }
1188+ var result = Radio.App.database.get_station_by_id (id);
1189+ if (result != null)
1190+ selected_stations.add (result);
1191+
1192 }
1193 }
1194
1195@@ -114,9 +108,22 @@
1196
1197 private void add_row (Radio.Station station) {
1198 Gtk.TreeIter iter;
1199+
1200+ string genre_text = "";
1201+ int arraylist_size = station.genres.size;
1202+
1203+ for (int i=0; i<arraylist_size; i++) {
1204+ genre_text = genre_text+station.genres [i];
1205+ if (i != arraylist_size - 1)
1206+ genre_text = genre_text + ", ";
1207+ }
1208+
1209 list_source.append(out iter);
1210 list_source.set_value(iter,0,station.name);
1211- list_source.set_value(iter,1,station.genre);
1212+ if (genre_text != "")
1213+ list_source.set_value(iter,1,genre_text);
1214+ else
1215+ list_source.set_value(iter,1,"Unknown");
1216 list_source.set_value(iter,2,station.url);
1217 list_source.set_value(iter,3,station.id);
1218 }
1219
1220=== modified file 'src/stations.vala'
1221--- src/stations.vala 2014-07-04 14:55:39 +0000
1222+++ src/stations.vala 2014-09-17 09:38:41 +0000
1223@@ -62,8 +62,8 @@
1224 }
1225
1226 public void update (Radio.Station station) throws Radio.Error {
1227-
1228- string query = @"UPDATE Stations SET Name=? , URL=? , Genre=? WHERE ID=?";
1229+ // TODO fix genre for db v2
1230+ /*string query = @"UPDATE Stations SET Name=? , URL=? , Genre=? WHERE ID=?";
1231
1232 Sqlite.Statement stmt;
1233 var query_status = db.prepare_v2 (query,query.length,out stmt);
1234@@ -78,7 +78,7 @@
1235 "Couldn't Update Entry: Error Code %d \nError Message: %s\n".printf(db.errcode (),db.errmsg ()));
1236 }
1237
1238- stmt.step ();
1239+ stmt.step ();*/
1240 }
1241
1242 public void delete (int id) throws Radio.Error {
1243@@ -174,7 +174,7 @@
1244
1245 private Gee.ArrayList<Radio.Station> select (string query) throws Radio.Error {
1246
1247- Sqlite.Statement stmt;
1248+ /*Sqlite.Statement stmt;
1249 var query_status = db.prepare_v2 (query,query.length,out stmt);
1250
1251 if (query_status != Sqlite.OK) {
1252@@ -225,6 +225,9 @@
1253 }
1254 } while (rc == Sqlite.ROW);
1255
1256- return stations_list;
1257+ return stations_list;*/
1258+
1259+ //temp
1260+ return new Gee.ArrayList<Radio.Station> ();
1261 }
1262 }

Subscribers

People subscribed via source and target branches