[gnome-music/freeze-break: 59/107] added playlistdialog.ui



commit f8e2b426ea1a4ea21859dc618d35160f986ff947
Author: Sai <suman sai14 gmail com>
Date:   Mon Aug 19 23:56:01 2013 +0530

    added playlistdialog.ui

 data/PlaylistDialog.ui         |   50 +++++++++++++++++++++++++++++
 data/gnome-music.gresource.xml |    1 +
 gnomemusic/grilo.py            |    5 ++-
 gnomemusic/view.py             |    9 -----
 gnomemusic/widgets.py          |   67 ++++++++++++++++++++++++++++-----------
 5 files changed, 103 insertions(+), 29 deletions(-)
---
diff --git a/data/PlaylistDialog.ui b/data/PlaylistDialog.ui
new file mode 100644
index 0000000..eed6dde
--- /dev/null
+++ b/data/PlaylistDialog.ui
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.10 -->
+  <object class="GtkDialog" id="dialog1">
+    <property name="can_focus">False</property>
+    <property name="type">popup</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox1">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area1">
+            <property name="can_focus">False</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+  <object class="GtkHeaderBar" id="headerbar1">
+    <property name="title" translatable="yes">Select Playlist</property>
+    <child>
+      <object class="GtkButton" id="cancel-button">
+        <property name="label" translatable="yes">Cancel</property>
+      </object>
+      <packing>
+          <property name="pack-type">start</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkButton" id="select-button">
+        <property name="label" translatable="yes">Select</property>
+        <style>
+          <class name="suggested-action"/>
+          <class name="text-button"/>
+        </style>
+      </object>
+      <packing>
+          <property name="pack-type">end</property>
+      </packing>
+    </child>
+  </object>
+</interface>
diff --git a/data/gnome-music.gresource.xml b/data/gnome-music.gresource.xml
index 4208373..b33c23d 100644
--- a/data/gnome-music.gresource.xml
+++ b/data/gnome-music.gresource.xml
@@ -13,5 +13,6 @@
     <file preprocess="xml-stripblanks">TrackWidget.ui</file>
     <file preprocess="xml-stripblanks">NoMusic.ui</file>
     <file preprocess="xml-stripblanks">PlaylistControls.ui</file>
+    <file preprocess="xml-stripblanks">PlaylistDialog.ui</file>
   </gresource>
 </gresources>
diff --git a/gnomemusic/grilo.py b/gnomemusic/grilo.py
index 13d77f0..16abdf0 100644
--- a/gnomemusic/grilo.py
+++ b/gnomemusic/grilo.py
@@ -50,7 +50,10 @@ class Grilo(GObject.GObject):
 
     def __init__(self):
         GObject.GObject.__init__(self)
-
+        self.playlist_path = GLib.build_filenamev([GLib.get_user_data_dir(),
+                                                  "gnome-music", "playlists"])
+        if not (GLib.file_test(self.playlist_path, GLib.FileTest.IS_DIR)):
+            GLib.mkdir_with_parents(self.playlist_path, int("0755", 8))
         self.options = Grl.OperationOptions()
         self.options.set_flags(Grl.ResolutionFlags.FULL |
                                Grl.ResolutionFlags.IDLE_RELAY)
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index 2205b05..72a248c 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -470,13 +470,6 @@ class Playlist(ViewContainer):
     def __init__(self, header_bar, selection_toolbar, player):
         ViewContainer.__init__(self, _("Playlists"), header_bar,
                                selection_toolbar)
-        self._playlistWidget = Gtk.Frame(
-            shadow_type=Gtk.ShadowType.NONE,
-            hexpand=True
-        )
-        self.add_button = Gtk.Button(label=_("Add"), visible=True)
-        self.view.get_parent().add(self.add_button)
-        self.add_button.show()
         self._playlist_list = {}
         self.view.set_view_type(Gd.MainViewType.LIST)
         self.view.set_hexpand(False)
@@ -484,7 +477,6 @@ class Playlist(ViewContainer):
             Gtk.SelectionMode.SINGLE)
         self._grid.attach(Gtk.Separator(orientation=Gtk.Orientation.VERTICAL),
                           1, 0, 1, 1)
-        self._grid.attach(self._playlistWidget, 2, 0, 2, 2)
         self._add_list_renderers()
         if (Gtk.Settings.get_default().get_property(
                 'gtk_application_prefer_dark_theme')):
@@ -493,7 +485,6 @@ class Playlist(ViewContainer):
         else:
             self.view.get_generic_view().get_style_context().\
                 add_class("artist-panel-white")
-        self.add_button.connect("clicked", self._on_add_button_clicked)
 
     def _add_list_renderers(self):
         list_widget = self.view.get_generic_view()
diff --git a/gnomemusic/widgets.py b/gnomemusic/widgets.py
index 3c2ba87..5705398 100644
--- a/gnomemusic/widgets.py
+++ b/gnomemusic/widgets.py
@@ -39,7 +39,9 @@ from gettext import gettext as _
 from gnomemusic.grilo import grilo
 from gnomemusic.query import Query
 from gnomemusic.albumArtCache import AlbumArtCache
+from gnomemusic.playlists import Playlists
 
+playlist = Playlists.get_default()
 tracker = Tracker.SparqlConnection.get(None)
 ALBUM_ART_CACHE = AlbumArtCache.get_default()
 if Gtk.Widget.get_default_direction() is not Gtk.TextDirection.RTL:
@@ -251,8 +253,8 @@ class AlbumWidget(Gtk.EventBox):
         #self.emit('loaded')
 
     def _on_add_to_playlist_button_clicked(self, widget):
-        self.dialog = PlaylistDialog()
-        self.dialog.run()
+        self.playlists = PlaylistDialog()
+        self.playlists.dialog_box.run()
 
     def _on_view_selection_changed(self, widget):
         items = self.view.get_selection()
@@ -441,31 +443,58 @@ class ArtistAlbums(Gtk.VBox):
         return False
 
 
-class PlaylistDialog(Gtk.Dialog):
+class PlaylistDialog():
     def __init__(self):
-        Gtk.Dialog.__init__(self, "My Dialog", None, 0)
-
-        self.set_default_size(150, 100)
-        self._cancel_button = Gtk.Button(label=_("Cancel"))
-        self._select_button = Gtk.Button(label=_("Select"))
-        self._select_button.get_style_context().add_class("suggested-action")
-        label = Gtk.Label("This is a dialog to display additional information")
-        self.title_bar = Gtk.HeaderBar()
-        self.title_bar.set_title(_("Select Playlist"))
-        self.title_bar.pack_start(self._cancel_button)
-        self.title_bar.pack_end(self._select_button)
-        self.set_titlebar(self.title_bar)
-        box = self.get_content_area()
-        box.add(label)
+        self.ui = Gtk.Builder()
+        self.ui.add_from_resource('/org/gnome/Music/PlaylistDialog.ui')
+        self.dialog_box = self.ui.get_object('dialog1')
+        self.dialog_box.set_default_size(300, 500)
+        self._cancel_button = self.ui.get_object('cancel-button')
+        self._select_button = self.ui.get_object('select-button')
+        self.view = Gtk.TreeView()
+        self.model = Gtk.ListStore(str)
+        playlist_names = playlist.get_playlists()
+        self.populate(playlist_names)
+        self.view.set_model(self.model)
+        self.title_bar = self.ui.get_object('headerbar1')
+        self.dialog_box.set_titlebar(self.title_bar)
+        box = self.dialog_box.get_content_area()
+        self._add_list_renderers()
+        box.add(self.view)
+        self.view.connect('row-activated', self._on_item_activated)
         self._cancel_button.connect('clicked', self._on_cancel_button_clicked)
         self._select_button.connect('clicked', self._on_selection)
-        self.show_all()
+        self.dialog_box.show_all()
+
+    def _add_list_renderers(self):
+        cols = Gtk.TreeViewColumn()
+        type_renderer = Gd.StyledTextRenderer(
+            xpad=16,
+            ypad=16,
+            ellipsize=Pango.EllipsizeMode.END,
+            xalign=0.0,
+            width=220
+        )
+        # self.view.add_renderer(type_renderer, lambda *args: None, None)
+        cols.clear_attributes(type_renderer)
+        cols.add_attribute(type_renderer, "text", 0)
+        self.view.append_column(cols)
+
+    def populate(self, items):
+        for playlist_name in items:
+            self.model.append([playlist_name])
+            # self.model.set(_iter, [0], )
+        add_playlist_iter = self.model.append()
+        self.model.set(add_playlist_iter, [0], [_("New Playlist")])
 
     def _on_selection(self, select_button):
         pass
 
     def _on_cancel_button_clicked(self, cancel_button):
-        self.destroy()
+        self.dialog_box.destroy()
+
+    def _on_item_activated(self, widget, item_id, path):
+        pass
 
 
 class AllArtistsAlbums(ArtistAlbums):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]