py::gui::album::file Class Reference

List of all members.

Public Member Functions

def __init__
def hide_field
def show_field
def adjust_field
def setup_ui
def edit_album
def copy_album
def unedit_album
def save
def action_add_to_library
def action_remove_from_library
def action_move_to_library
def link_slot
def reload
def show_album
def show_item

Public Attributes

 field_layout
 actions_hbox
 actions
 editor_url
 cover
 item
 comment_file

Static Public Attributes

list fields
 album = None
 albumcopy = None


Member Function Documentation

def py::gui::album::file::__init__ (   self  ) 

00194                              :
00195                 Ui_album_file.__init__(self)
00196                 QWidget.__init__(self)
00197                 self.setup_ui()
00198 
        def hide_field( self, field ) :

def py::gui::album::file::hide_field (   self,
  field 
)

00199                                       :
00200                 line = getattr(self,"%s_line"%field)
00201                 for i in range(0,line.count()) :
00202                         w = line.itemAt(i).widget()
00203                         if w :
00204                                 w.hide()
00205         
        def show_field( self, field ) :

def py::gui::album::file::show_field (   self,
  field 
)

00206                                       :
00207                 line = getattr(self,"%s_line"%field)
00208                 for i in range(0,line.count()) :
00209                         w = line.itemAt(i).widget()
00210                         if w :
00211                                 w.show()
00212         
        def adjust_field( self, name ) :

def py::gui::album::file::adjust_field (   self,
  name 
)

00213                                        :
00214                 field = getattr(self,name)
00215                 field.setFixedWidth(3+field.fontMetrics().width(field.displayText()))
00216 
        def setup_ui( self ) :

def py::gui::album::file::setup_ui (   self  ) 

00217                              :
00218                 self.setupUi(self)
00219                 self.field_layout = self.vboxlayout2
00220                 palette = self.palette()
00221                 palette.setColor(QPalette.Base,palette.window().color())
00222                 palette.setColor(QPalette.Text,palette.windowText().color())
00223 
00224                 # link hboxlayouts
00225                 self.actions_hbox = self.hboxlayout
00226                 for i in range(0,len(self.fields)) :
00227                         field = self.fields[i]
00228                         setattr(self,"%s_line"%field,getattr(self,"hboxlayout%d"%(2+i)))
00229                         getattr(self,field).setPalette(palette)
00230 
00231                 self.actions = gui.widget.actions_layout(self.actions_hbox)
00232 
00233                 self.editor_url = gui.widget.link_label()
00234                 self.editor_line.insertWidget(2, self.editor_url)
00235 
00236                 self.cover = cover(self.image_frame, 150, 200)
00237 
00238                 if not qocfg.get_debug() :
00239                         self.tabs.removeTab(self.tabs.indexOf(self.tab_debug))
00240 
00241                 self.connect(self.button_edit, SIGNAL("clicked()"), self.edit_album)
00242                 self.connect(self.button_copy, SIGNAL("clicked()"), self.copy_album)
00243                 self.connect(self.button_delete, SIGNAL("clicked()"), self.unedit_album)
00244 
00245         @gui.dialog.show_failure
        def edit_album( self ) :

def py::gui::album::file::edit_album (   self  ) 

00246                                :
00247                 ret = gui.editor.album(self, self.album).exec_()
00248 
00249         @gui.dialog.show_failure
        def copy_album( self ) :

def py::gui::album::file::copy_album (   self  ) 

00250                                :
00251                 ret = gui.editor.album(self, None, self.album).exec_()
00252         
00253         @gui.dialog.show_failure
        def unedit_album( self ) :

def py::gui::album::file::unedit_album (   self  ) 

00254                                  :
00255                 if self.album.created_by_user :
00256                         if self.album.albumcopy_set.count() :
00257                                 QMessageBox.warning(self, _("Cannot delete album"), 
00258                                         _("""There is album copies of this album present in your collections and/or shopping lists.
00259 You can't delete this album"""))
00260                         else :
00261                                 if QMessageBox.information(self, _("Delete album?"),
00262                                                 _("""This album has been created by you. Are you sure you want to delete it?"""),
00263                                                 QMessageBox.No, QMessageBox.Yes) == QMessageBox.Yes :
00264                                         self.album.delete()
00265                                         self.album = None
00266                                         self.hide()
00267                 else :
00268                         self.album.unoverlay()
00269                         gui.models.manager.update_entity(self.album)
00270         
        def save( self ) :

def py::gui::album::file::save (   self  ) 

00271                          :
00272                 if not self.album :
00273                         return
00274                 if hasattr(self, "comment_file") :
00275                         comment = unicode(self.comment.toPlainText())
00276                         if len(comment.strip()) :
00277                                 codecs.open(self.comment_file,"wb","utf-8").write(comment)
00278                         else :
00279                                 qo.sh.rmf(self.comment_file)
00280         
00281         @gui.dialog.show_failure
        def action_add_to_library( self, library_id ) :

def py::gui::album::file::action_add_to_library (   self,
  library_id 
)

00282                                                       :
00283                 albumcopy = Library.objects.get(id=library_id).albums.create(album=self.album)
00284                 gui.models.manager.register_albumcopy(albumcopy)
00285 
00286         @gui.dialog.show_failure
        def action_remove_from_library( self, library_id ) :

def py::gui::album::file::action_remove_from_library (   self,
  library_id 
)

00287                                                            :
00288                 copies = []
00289                 if self.albumcopy :
00290                         copies.append(self.albumcopy)
00291                 else :
00292                         copies = list(self.album.albumcopy_set.filter(library=library_id))
00293                 doit = True
00294                 if len(copies) > 1 :
00295                         libname = copies[0].library.name
00296                         album = copies[0].album
00297                         if album.series.is_oneshot() :
00298                                 disp = album.name
00299                         else :
00300                                 disp = "%s (%s)" % (album.name, album.series)
00301                         doit = QMessageBox.question(self, _("Removal confirmation"), 
00302                                         _("You are about to remove %d copy of %s from %s.")%(len(copies),disp,libname), 
00303                                         QMessageBox.Ok, QMessageBox.Cancel) == QMessageBox.Ok
00304                 if doit :
00305                         for copy in copies :
00306                                 album = copy.album
00307                                 copy_id = copy.id
00308                                 copy.delete()
00309                                 gui.models.manager.unregister_albumcopy(library_id, copy_id, album)
00310 
00311         @gui.dialog.show_failure
        def action_move_to_library( self, library_id ) :

def py::gui::album::file::action_move_to_library (   self,
  library_id 
)

00312                                                        :
00313                 copies = []
00314                 if self.albumcopy :
00315                         copies.append(self.albumcopy)
00316                 else :
00317                         copies = list(self.album.albumcopy_set.exclude(library=library_id))
00318                 for copy in copies :
00319                         old_library_id = copy.library.id
00320                         copy.library = Library.objects.get(id=library_id)
00321                         copy.save()
00322                         gui.models.manager.move_albumcopy(copy, old_library_id, library_id)
00323 
        def link_slot( self, slotname, arg ) :

def py::gui::album::file::link_slot (   self,
  slotname,
  arg 
)

00324                                              :
00325                 cslotname = "%s_%s"%(slotname,arg)
00326                 if not hasattr(self, cslotname) :
00327                         setattr(self, cslotname, lambda : getattr(self, slotname)(arg))
00328                 return getattr(self, cslotname)
00329         
        def reload( self ) :

def py::gui::album::file::reload (   self  ) 

00330                            :
00331                 if hasattr(self, "item") :
00332                         self.show_item(self.item)
00333 
00334         @gui.dialog.show_failure
        def show_album( self, item ) :

def py::gui::album::file::show_album (   self,
  item 
)

00335                                      :
00336                 # save previous album
00337                 self.save()
00338 
00339                 # setup
00340                 self.item = item
00341                 self.album = item.album
00342                 self.albumcopy = None
00343                 if hasattr(item, "albumcopy") :
00344                         self.albumcopy = item.albumcopy
00345 
00346                 # actions
00347                 self.actions.clear()
00348                 may_add = not self.album.is_nextout()
00349                 if not self.albumcopy :
00350                         in_libraries = map(operator.itemgetter("library"), self.album.albumcopy_set.distinct().values('library'))
00351                 else :
00352                         in_libraries = [self.albumcopy.library.id]
00353 
00354                 if qodb.cte.main_library_id in in_libraries :
00355                         self.actions.add(_("Duplicate copy"), self.link_slot("action_add_to_library", qodb.cte.main_library_id))
00356                         self.actions.add(_("Remove from %s")%_("My comics"), self.link_slot("action_remove_from_library", qodb.cte.main_library_id))
00357                 else :
00358                         if qodb.cte.shopping_list_id in in_libraries :
00359                                 if may_add :
00360                                         self.actions.add(_("Move to %s")%_("My comics"), self.link_slot("action_move_to_library", qodb.cte.main_library_id))
00361                                 self.actions.add(_("Remove from %s")%_("Shopping list"), self.link_slot("action_remove_from_library",
00362                                                                         qodb.cte.shopping_list_id))
00363                         else :
00364                                 if may_add :
00365                                         self.actions.add(_("Add to %s")%_("My comics"), self.link_slot("action_add_to_library", qodb.cte.main_library_id))
00366                                 self.actions.add(_("Add to %s")%_("Shopping list"), self.link_slot("action_add_to_library", qodb.cte.shopping_list_id))
00367 
00368                 self.button_delete.setEnabled(self.album.created_by_user or self.album.modified_by_user)
00369 
00370                 def set_field(name, data) :
00371                         if data :
00372                                 getattr(self,name).setText(data)
00373                                 self.show_field(name)
00374                         else :
00375                                 self.hide_field(name)
00376                 if self.album.series.is_oneshot() :
00377                         set_field("series",None)
00378                 else :
00379                         set_field("series",self.album.series.name)
00380                 set_field("name",self.album.name)
00381                 if self.album.volume :
00382                         set_field("volume",str(self.album.volume))
00383                 else :
00384                         set_field("volume",None)
00385                 set_field("author",self.album.authors_str)
00386                 set_field("drawer",self.album.drawers_str)
00387                 set_field("editor",self.album.series.collection.editor.name)
00388                 set_field("collection",self.album.series.collection.name)
00389                 set_field("published_date",self.album.published_date_str)
00390                 set_field("isbn",self.album.isbn)
00391                 set_field("ean",self.album.ean)
00392                 if self.album.guiding_price :
00393                         set_field("guiding_price",str(self.album.guiding_price))
00394                 else :
00395                         set_field("guiding_price",None)
00396 
00397                 # adjust fields size
00398                 self.adjust_field("editor")
00399                 self.adjust_field("guiding_price")
00400 
00401                 # special fields
00402                 self.editor_url.setText(self.album.series.collection.editor.homepage)
00403 
00404                 # cover
00405                 self.cover.show_cover("%s#cover"%self.album.qoid)
00406 
00407                 # tabs
00408                 if qocfg.get_debug() :
00409                         self.debug.setHtml("""qoid = %s
00410 """ % self.album.qoid)
00411 
00412                 d = {}
00413                 if self.albumcopy :
00414                         d["copyid"] = self.albumcopy.id
00415                 self.comment_file = qocfg.get_comment_path(self.album.qoid, **d)
00416                 self.comment.clear()
00417                 if os.path.exists(self.comment_file) :
00418                         try :
00419                                 self.comment.setPlainText(codecs.open(self.comment_file,"rb","utf-8").read())
00420                         except :
00421                                 traceback.print_exc()
00422                 elif self.albumcopy :
00423                         self.comment_file = qocfg.get_copy_comment_path(self.album.qoid, **d)
00424 
00425 
        def show_item( self, item ) :

def py::gui::album::file::show_item (   self,
  item 
)

00426                                     :
00427                 self.setUpdatesEnabled(False)
00428                 try :
00429                         self.show_album(item)
00430                 finally :
00431                         self.setUpdatesEnabled(True)
00432 
00433 


Member Data Documentation

list py::gui::album::file::fields [static]

Initial value:

['series', 'name', 'volume', 'author', 'drawer', 'editor', 'collection', 'published_date',
                                'isbn', 'ean', 'guiding_price']

py::gui::album::file::album = None [static]

py::gui::album::file::albumcopy = None [static]

py::gui::album::file::field_layout

py::gui::album::file::actions_hbox

py::gui::album::file::actions

py::gui::album::file::editor_url

py::gui::album::file::cover

py::gui::album::file::item

py::gui::album::file::comment_file


The documentation for this class was generated from the following file:
Generated on Tue Oct 9 20:40:24 2007 for Qomics by  doxygen 1.5.3