[pitivi: 25/41] Initialize project metadata properly and load them into the ProjectSettings dialog



commit a31e63fe0c928c8c8e1f76355465bc215983484d
Author: StÃphane Maniaci <stephane maniaci gmail com>
Date:   Thu Jun 30 20:29:37 2011 +0200

    Initialize project metadata properly and load them into the ProjectSettings dialog

 pitivi/project.py            |    2 ++
 pitivi/projectmanager.py     |    5 +++++
 pitivi/ui/mainwindow.py      |   24 +++++++++++++++---------
 pitivi/ui/projectsettings.py |   32 +++++++++++++++++++++-----------
 4 files changed, 43 insertions(+), 20 deletions(-)
---
diff --git a/pitivi/project.py b/pitivi/project.py
index f68da48..298dc71 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -77,6 +77,8 @@ class Project(Signallable, Loggable):
         Loggable.__init__(self)
         self.log("name:%s, uri:%s", name, uri)
         self.name = name
+        self.author = ""
+        self.year = ""
         self.settings = None
         self.description = ""
         self.uri = uri
diff --git a/pitivi/projectmanager.py b/pitivi/projectmanager.py
index 769046a..6843676 100644
--- a/pitivi/projectmanager.py
+++ b/pitivi/projectmanager.py
@@ -26,6 +26,7 @@ import gst
 import os
 
 from urlparse import urlparse
+from pwd import getpwuid
 
 from pitivi.project import Project
 from pitivi.formatters.format import get_formatter_for_uri
@@ -179,6 +180,10 @@ class ProjectManager(Signallable, Loggable):
         # we don't have an URI here, None means we're loading a new project
         self.emit("new-project-loading", None)
         project = Project(_("New Project"))
+
+        # setting default values for project metadata
+        project.author = getpwuid(os.getuid()).pw_gecos.split(",")[0]
+
         self.emit("new-project-created", project)
         self.current = project
 
diff --git a/pitivi/ui/mainwindow.py b/pitivi/ui/mainwindow.py
index 891783f..c82bf98 100644
--- a/pitivi/ui/mainwindow.py
+++ b/pitivi/ui/mainwindow.py
@@ -594,7 +594,8 @@ class PitiviMainWindow(gtk.Window, Loggable):
 
     def showProjectSettingsDialog(self):
         from projectsettings import ProjectSettingsDialog
-        ProjectSettingsDialog(self, self.app.current).window.show()
+        ProjectSettingsDialog(self, self.app.current).window.run()
+        self.updateTitle()
 
     def _quitCb(self, unused_action):
         self._saveWindowSettings()
@@ -976,14 +977,7 @@ class PitiviMainWindow(gtk.Window, Loggable):
         redo_action = self.actiongroup.get_action("Redo")
         can_redo = bool(action_log.redo_stacks)
         redo_action.set_sensitive(can_redo)
-
-        if self.project is not None:
-            app_name = "%s" % (APPNAME)
-            title = u"%s \u2014 %s" % (self.project.name, app_name)
-            if dirty:
-                title = "*" + title
-            title = title.encode("utf8")
-            self.set_title(title)
+        self.updateTitle()
 
 ## PiTiVi current project callbacks
 
@@ -1148,3 +1142,15 @@ class PitiviMainWindow(gtk.Window, Loggable):
             self.project.pipeline.seek(position, format)
         except:
             self.debug("Seeking failed")
+
+    def updateTitle(self):
+        name = touched = ""
+        if self.project:
+            if self.project.name:
+                name = self.project.name
+            else:
+                name = _("Untitled project")
+            if self.project.hasUnsavedModifications():
+                touched = "*"
+        title = u"%s%s \u2014 %s" % (touched, name, APPNAME)
+        self.set_title(title)
diff --git a/pitivi/ui/projectsettings.py b/pitivi/ui/projectsettings.py
index 28799cb..6bf111a 100644
--- a/pitivi/ui/projectsettings.py
+++ b/pitivi/ui/projectsettings.py
@@ -27,8 +27,9 @@ Dialog box for project settings
 import gtk
 import gst
 import os
-from pwd import getpwuid
+
 from datetime import datetime
+
 from pitivi.configure import get_ui_dir
 from gettext import gettext as _
 from pitivi.ui.dynamic import FractionWidget
@@ -111,16 +112,7 @@ class ProjectSettingsDialog():
         self.sample_rate_combo.set_model(audio_rates)
         self.sample_depth_combo.set_model(audio_depths)
 
-        # set the project metadata
-        # FIXME: not saved in the project file
-        if self.year_spinbutton.get_value_as_int() == 1900:
-            self.year_spinbutton.set_value(datetime.now().year)
-        if self.author_entry.get_text() == "":
-            self.full_user_name = getpwuid(os.getuid()).pw_gecos.split(",")[0]
-            self.author_entry.set_text(self.full_user_name)
-
         # behavior
-
         self.wg = RippleUpdateGroup()
         self.wg.addVertex(self.frame_rate_combo,
                 signal="changed",
@@ -398,6 +390,9 @@ class ProjectSettingsDialog():
             "video-preset-infobar")
         self.audio_preset_infobar = self.builder.get_object(
             "audio-preset-infobar")
+        self.title_entry = self.builder.get_object("title_entry")
+        self.author_entry = self.builder.get_object("author_entry")
+        self.year_spinbutton = self.builder.get_object("year_spinbutton")
 
     def _constrainSarButtonToggledCb(self, button):
         if button.props.active:
@@ -474,7 +469,7 @@ class ProjectSettingsDialog():
         self.save_video_preset_button.set_sensitive(preset_changed)
         preset_selected = bool(self.video_presets.cur_preset)
         self.remove_video_preset_button.set_sensitive(preset_selected)
-    
+
     def _updateAudioSaveButton(self, unused_in, button):
         button.set_sensitive(self.audio_presets.isCurrentPresetChanged())
 
@@ -537,6 +532,20 @@ class ProjectSettingsDialog():
 
         self._selectDarRadiobuttonToggledCb(self.select_dar_radiobutton)
 
+        # metadata
+        self.title_entry.set_text(self.project.name)
+        self.author_entry.set_text(self.project.author)
+        if self.project.year:
+            year = int(self.project.year)
+        else:
+            year = datetime.now().year
+        self.year_spinbutton.get_adjustment().set_value(year)
+
+    def updateMetadata(self):
+        self.project.name = self.title_entry.get_text()
+        self.project.author = self.author_entry.get_text()
+        self.project.year = str(self.year_spinbutton.get_adjustment().get_value())
+
     def updateSettings(self):
         width = int(self.width_spinbutton.get_value())
         height = int(self.height_spinbutton.get_value())
@@ -555,6 +564,7 @@ class ProjectSettingsDialog():
     def _responseCb(self, unused_widget, response):
         if response == gtk.RESPONSE_OK:
             self.updateSettings()
+            self.updateMetadata()
         self.audio_presets.save()
         self.video_presets.save()
         self.window.destroy()



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