~ubuntu-branches/ubuntu/karmic/calibre/karmic

« back to all changes in this revision

Viewing changes to src/calibre/gui2/dialogs/tag_editor.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-30 12:49:41 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730124941-qjdsmri25zt8zocn
Tags: 0.6.3+dfsg-0ubuntu1
* New upstream release. Please see http://calibre.kovidgoyal.net/new_in_6/
  for the list of new features and changes.
* remove_postinstall.patch: Update for new version.
* build_debug.patch: Does not apply any more, disable for now. Might not be
  necessary any more.
* debian/copyright: Fix reference to versionless GPL.
* debian/rules: Drop obsolete dh_desktop call.
* debian/rules: Add workaround for weird Python 2.6 setuptools behaviour of
  putting compiled .so files into src/calibre/plugins/calibre/plugins
  instead of src/calibre/plugins.
* debian/rules: Drop hal fdi moving, new upstream version does not use hal
  any more. Drop hal dependency, too.
* debian/rules: Install udev rules into /lib/udev/rules.d.
* Add debian/calibre.preinst: Remove unmodified
  /etc/udev/rules.d/95-calibre.rules on upgrade.
* debian/control: Bump Python dependencies to 2.6, since upstream needs
  it now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
__license__   = 'GPL v3'
2
2
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
3
3
from PyQt4.QtCore import SIGNAL, Qt
4
 
from PyQt4.QtGui import QDialog, QMessageBox
 
4
from PyQt4.QtGui import QDialog
5
5
 
6
6
from calibre.gui2.dialogs.tag_editor_ui import Ui_TagEditor
7
7
from calibre.gui2 import qstring_to_unicode
8
8
from calibre.gui2 import question_dialog, error_dialog
9
9
 
10
10
class TagEditor(QDialog, Ui_TagEditor):
11
 
    
 
11
 
12
12
    def __init__(self, window, db, index=None):
13
13
        QDialog.__init__(self, window)
14
14
        Ui_TagEditor.__init__(self)
15
15
        self.setupUi(self)
16
 
        
 
16
 
17
17
        self.db = db
18
18
        self.index = index
19
19
        if self.index is not None:
27
27
                self.applied_tags.addItem(tag)
28
28
        else:
29
29
            tags = []
30
 
        
 
30
 
31
31
        self.tags = tags
32
 
        
 
32
 
33
33
        all_tags = [tag for tag in self.db.all_tags()]
34
34
        all_tags = list(set(all_tags))
35
35
        all_tags.sort()
36
36
        for tag in all_tags:
37
37
            if tag not in tags:
38
38
                self.available_tags.addItem(tag)
39
 
                
 
39
 
40
40
        self.connect(self.apply_button,   SIGNAL('clicked()'), self.apply_tags)
41
41
        self.connect(self.unapply_button, SIGNAL('clicked()'), self.unapply_tags)
42
42
        self.connect(self.add_tag_button, SIGNAL('clicked()'), self.add_tag)
44
44
        self.connect(self.add_tag_input,  SIGNAL('returnPressed()'), self.add_tag)
45
45
        self.connect(self.available_tags, SIGNAL('itemActivated(QListWidgetItem*)'), self.apply_tags)
46
46
        self.connect(self.applied_tags,   SIGNAL('itemActivated(QListWidgetItem*)'), self.unapply_tags)
47
 
        
48
 
    
 
47
 
 
48
 
49
49
    def delete_tags(self, item=None):
50
50
        confirms, deletes = [], []
51
51
        items = self.available_tags.selectedItems() if item is None else [item]
56
56
            if self.db.is_tag_used(qstring_to_unicode(item.text())):
57
57
                confirms.append(item)
58
58
            else:
59
 
                deletes.append(item)    
 
59
                deletes.append(item)
60
60
        if confirms:
61
61
            ct = ', '.join([qstring_to_unicode(item.text()) for item in confirms])
62
 
            d = question_dialog(self, 'Are your sure?', 
63
 
                                '<p>The following tags are used by one or more books. Are you certain you want to delete them?<br>'+ct)
64
 
            if d.exec_() == QMessageBox.Yes:
 
62
            if question_dialog(self, _('Are your sure?'),
 
63
                '<p>'+_('The following tags are used by one or more books. '
 
64
                    'Are you certain you want to delete them?')+'<br>'+ct):
65
65
                deletes += confirms
66
 
        
 
66
 
67
67
        for item in deletes:
68
68
            self.db.delete_tag(qstring_to_unicode(item.text()))
69
69
            self.available_tags.takeItem(self.available_tags.row(item))
70
 
        
71
 
    
 
70
 
 
71
 
72
72
    def apply_tags(self, item=None):
73
 
        items = self.available_tags.selectedItems() if item is None else [item]  
 
73
        items = self.available_tags.selectedItems() if item is None else [item]
74
74
        for item in items:
75
75
            tag = qstring_to_unicode(item.text())
76
76
            self.tags.append(tag)
77
77
            self.available_tags.takeItem(self.available_tags.row(item))
78
 
        
 
78
 
79
79
        self.tags.sort()
80
80
        self.applied_tags.clear()
81
81
        for tag in self.tags:
82
82
            self.applied_tags.addItem(tag)
83
 
                
84
 
            
85
 
    
 
83
 
 
84
 
 
85
 
86
86
    def unapply_tags(self, item=None):
87
 
        items = self.applied_tags.selectedItems() if item is None else [item] 
 
87
        items = self.applied_tags.selectedItems() if item is None else [item]
88
88
        for item in items:
89
89
            tag = qstring_to_unicode(item.text())
90
90
            self.tags.remove(tag)
91
91
            self.available_tags.addItem(tag)
92
 
            
 
92
 
93
93
        self.tags.sort()
94
94
        self.applied_tags.clear()
95
95
        for tag in self.tags:
96
96
            self.applied_tags.addItem(tag)
97
 
            
 
97
 
98
98
        self.available_tags.sortItems()
99
 
    
 
99
 
100
100
    def add_tag(self):
101
101
        tags = qstring_to_unicode(self.add_tag_input.text()).split(',')
102
102
        for tag in tags:
105
105
                self.available_tags.takeItem(self.available_tags.row(item))
106
106
            if tag not in self.tags:
107
107
                self.tags.append(tag)
108
 
                
 
108
 
109
109
        self.tags.sort()
110
110
        self.applied_tags.clear()
111
111
        for tag in self.tags:
112
112
            self.applied_tags.addItem(tag)
113
 
            
 
113
 
114
114
        self.add_tag_input.setText('')