~ubuntu-branches/ubuntu/maverick/backintime/maverick

« back to all changes in this revision

Viewing changes to kde4snapshotsdialog.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Wiltshire
  • Date: 2009-05-16 23:04:32 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090516230432-orrutvtufbtuxsc6
Tags: 0.9.24-1
* New upstream version (closes: #527447):
  - backintime is no longer aware of 'backintime-gnome' and 'backintime-kde4'
    (you need run 'backintime-gnome' for GNOME version and 'backintime-kde4'
    for KDE4 version)
  - fix a bug that crashes the program after taking a snapshot
* Update homepage field in debian/control (closes: #527595)
* Refactor packaging to fit new upstream build system (an almost entire 
  re-write of debian/rules)
* Make configure scripts use /bin/sh instead of /bin/bash (they don't use
  bash features)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#    Back In Time
2
 
#    Copyright (C) 2008-2009 Oprea Dan
3
 
#
4
 
#    This program is free software; you can redistribute it and/or modify
5
 
#    it under the terms of the GNU General Public License as published by
6
 
#    the Free Software Foundation; either version 2 of the License, or
7
 
#    (at your option) any later version.
8
 
#
9
 
#    This program is distributed in the hope that it will be useful,
10
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
#    GNU General Public License for more details.
13
 
#
14
 
#    You should have received a copy of the GNU General Public License along
15
 
#    with this program; if not, write to the Free Software Foundation, Inc.,
16
 
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
 
 
18
 
 
19
 
import os
20
 
import os.path
21
 
import sys
22
 
import datetime
23
 
import gettext
24
 
 
25
 
from PyQt4.QtGui import *
26
 
from PyQt4.QtCore import *
27
 
from PyKDE4.kdecore import *
28
 
from PyKDE4.kdeui import *
29
 
from PyKDE4.kio import *
30
 
 
31
 
import config
32
 
import tools
33
 
import kde4tools
34
 
 
35
 
 
36
 
_=gettext.gettext
37
 
 
38
 
 
39
 
class DiffOptionsDialog( KDialog ):
40
 
        def __init__( self, parent ):
41
 
                KDialog.__init__( self, parent )
42
 
                self.config = parent.config
43
 
 
44
 
                self.setWindowIcon( KIcon( 'configure' ) )
45
 
                self.setCaption( QString.fromUtf8( _( 'Diff Options' ) ) )
46
 
 
47
 
                self.main_widget = QWidget( self )
48
 
                self.main_layout = QGridLayout()
49
 
                self.main_widget.setLayout( self.main_layout )
50
 
                self.setMainWidget( self.main_widget )
51
 
 
52
 
                self.diff_cmd = self.config.get_str_value( 'kde4.diff.cmd', 'kompare' )
53
 
                self.diff_params = self.config.get_str_value( 'kde4.diff.params', '%1 %2' )
54
 
 
55
 
                self.main_layout.addWidget( QLabel( QString.fromUtf8( _( 'Command:' ) ) ), 0, 0 )
56
 
                self.edit_command = KLineEdit( self.diff_cmd, self )
57
 
                self.main_layout.addWidget( self.edit_command, 0, 1 )
58
 
 
59
 
                self.main_layout.addWidget( QLabel( QString.fromUtf8( _( 'Parameters:' ) ) ), 1, 0 )
60
 
                self.edit_params = KLineEdit( self.diff_params, self )
61
 
                self.main_layout.addWidget( self.edit_params, 1, 1 )
62
 
 
63
 
                self.main_layout.addWidget( QLabel( QString.fromUtf8( _( 'Use %1 and %2 for path parameters' ) ) ), 2, 1 )
64
 
 
65
 
        def accept( self ):
66
 
                diff_cmd = str( self.edit_command.text() )
67
 
                diff_params = str( self.edit_params.text() )
68
 
 
69
 
                if diff_cmd != self.diff_cmd or diff_params != self.diff_params:
70
 
                        self.config.set_str_value( 'kde4.diff.cmd', diff_cmd )
71
 
                        self.config.set_str_value( 'kde4.diff.params', diff_params )
72
 
                        self.config.save()
73
 
                
74
 
                KDialog.accept( self )
75
 
 
76
 
 
77
 
class SnapshotsDialog( KDialog ):
78
 
        def __init__( self, parent, snapshot_id, path, icon ):
79
 
                KDialog.__init__( self, parent )
80
 
                self.config = parent.config
81
 
                self.snapshots = parent.snapshots
82
 
                self.snapshots_list = parent.snapshots_list
83
 
                self.kapp = parent.kapp
84
 
 
85
 
                self.snapshot_id = snapshot_id
86
 
                self.path = path 
87
 
                self.icon = icon
88
 
 
89
 
                self.setWindowIcon( KIcon( 'view-list-details' ) )
90
 
                self.setCaption( QString.fromUtf8( _( 'Snapshots' ) ) )
91
 
 
92
 
                #
93
 
                self.main_widget = QWidget( self )
94
 
                self.main_layout = QVBoxLayout()
95
 
                self.main_widget.setLayout( self.main_layout )
96
 
                self.setMainWidget( self.main_widget )
97
 
 
98
 
                #path
99
 
                self.edit_path = KLineEdit( self.path, self )
100
 
                self.edit_path.setReadOnly( True )
101
 
                self.main_layout.addWidget( self.edit_path )
102
 
 
103
 
                #toolbar
104
 
                self.toolbar = KToolBar( self )
105
 
                self.toolbar.setFloatable( False )
106
 
                self.main_layout.addWidget( self.toolbar )
107
 
 
108
 
                #toolbar restore
109
 
                self.btn_restore = self.toolbar.addAction( KIcon( 'document-revert' ), '' )
110
 
                self.btn_restore.setToolTip( QString.fromUtf8( _('Restore') ) )
111
 
                QObject.connect( self.btn_restore, SIGNAL('triggered()'), self.on_btn_restore_clicked )
112
 
 
113
 
                #toolbar copy
114
 
                self.btn_copy = self.toolbar.addAction( KIcon( 'edit-copy' ), '' )
115
 
                self.btn_copy.setToolTip( QString.fromUtf8( _('Copy') ) )
116
 
                QObject.connect( self.btn_copy, SIGNAL('triggered()'), self.on_btn_copy_to_clipboard_clicked )
117
 
 
118
 
                #snapshots list
119
 
                self.list_snapshots = KListWidget( self )
120
 
                self.main_layout.addWidget( self.list_snapshots )
121
 
                QObject.connect( self.list_snapshots, SIGNAL('currentItemChanged(QListWidgetItem*,QListWidgetItem*)'), self.on_list_snapshots_changed )
122
 
                QObject.connect( self.list_snapshots, SIGNAL('executed(QListWidgetItem*)'), self.on_list_snapshots_executed )
123
 
 
124
 
                #diff
125
 
                layout = QHBoxLayout()
126
 
                self.main_layout.addLayout( layout )
127
 
 
128
 
                self.btn_diff = KPushButton( QString.fromUtf8( _('Diff') ), self )
129
 
                layout.addWidget( self.btn_diff )
130
 
                QObject.connect( self.btn_diff, SIGNAL('clicked()'), self.on_btn_diff_clicked )
131
 
 
132
 
                self.combo_diff = KComboBox( self )
133
 
                layout.addWidget( self.combo_diff, 2 )
134
 
 
135
 
                #diff options
136
 
                self.setButtons( KDialog.ButtonCode( KDialog.Ok | KDialog.Cancel | KDialog.User1 ) )
137
 
                self.setButtonGuiItem( KDialog.User1, KGuiItem( QString.fromUtf8( _('Diff Options') ), KIcon( 'configure' ) ) )
138
 
                self.setButtonText( KDialog.Ok, QString.fromUtf8( _('Go To') ) )
139
 
 
140
 
                QObject.connect( self, SIGNAL('user1Clicked()'), self.on_btn_diff_options_clicked )
141
 
 
142
 
                self.setDefaultButton( KDialog.Ok )
143
 
 
144
 
                #update list and combobox
145
 
                self.update_snapshots()
146
 
 
147
 
        def add_snapshot_( self, snapshot_id, is_dir ):
148
 
                full_path = self.snapshots.get_snapshot_path_to( snapshot_id, self.path )
149
 
 
150
 
                if not os.path.exists( full_path ):
151
 
                        return
152
 
 
153
 
                if is_dir != os.path.isdir( full_path ):
154
 
                        return
155
 
 
156
 
                name = self.snapshots.get_snapshot_display_name( snapshot_id )
157
 
 
158
 
                #add to list
159
 
                item = QListWidgetItem( QString.fromUtf8( name ), self.list_snapshots )
160
 
                item.setData( Qt.UserRole, QVariant( snapshot_id ) )
161
 
 
162
 
                if self.list_snapshots.currentItem() is None:
163
 
                        self.list_snapshots.setCurrentItem( item )
164
 
 
165
 
                #add to combo
166
 
                self.combo_diff.addItem( QString.fromUtf8( name ), QVariant( snapshot_id ) )
167
 
 
168
 
                if self.snapshot_id == snapshot_id:
169
 
                        self.combo_diff.setCurrentIndex( self.combo_diff.count() - 1 )
170
 
                elif self.combo_diff.currentIndex() < 0:
171
 
                        self.combo_diff.setCurrentIndex( 0 )
172
 
 
173
 
        def update_snapshots( self ):
174
 
                self.list_snapshots.clear()
175
 
                self.combo_diff.clear()
176
 
        
177
 
                path = self.snapshots.get_snapshot_path_to( self.snapshot_id, self.path )       
178
 
                is_dir = os.path.isdir( path )
179
 
 
180
 
                #add now
181
 
                self.add_snapshot_( '/', is_dir )
182
 
                                
183
 
                #add snapshots
184
 
                for snapshot_id in self.snapshots_list:
185
 
                        self.add_snapshot_( snapshot_id, is_dir )
186
 
 
187
 
                self.update_toolbar()
188
 
 
189
 
        def get_list_snapshot_id( self ):
190
 
                item = self.list_snapshots.currentItem()
191
 
                if item is None:
192
 
                        return ''
193
 
                return str( item.data( Qt.UserRole ).toString() )
194
 
 
195
 
        def update_toolbar( self ):
196
 
                snapshot_id = self.get_list_snapshot_id()
197
 
 
198
 
                self.btn_copy.setEnabled( len( snapshot_id ) > 0 )
199
 
                self.btn_restore.setEnabled( len( snapshot_id ) > 1 )
200
 
 
201
 
        def on_btn_restore_clicked( self ):
202
 
                snapshot_id = self.get_list_snapshot_id()
203
 
                if len( snapshot_id ) > 1:
204
 
                        self.snapshots.restore( snapshot_id, self.path )
205
 
 
206
 
        def on_btn_copy_to_clipboard_clicked( self ):
207
 
                snapshot_id = self.get_list_snapshot_id()
208
 
                if len( snapshot_id ) < 1:
209
 
                        return
210
 
 
211
 
                path = self.snapshots.get_snapshot_path_to( snapshot_id, self.path )
212
 
                kde4tools.clipboard_set_path( self.kapp, path )
213
 
 
214
 
        def on_list_snapshots_changed( self ):
215
 
                self.update_toolbar()
216
 
 
217
 
        def on_list_snapshots_executed( self, item ):
218
 
                snapshot_id = self.get_list_snapshot_id()
219
 
                if len( snapshot_id ) <= 0:
220
 
                        return
221
 
 
222
 
                full_path = self.snapshots.get_snapshot_path_to( snapshot_id, self.path )
223
 
                self.run = KRun( KUrl( full_path ), self, True )
224
 
 
225
 
        def on_btn_diff_clicked( self ):
226
 
                snapshot_id = self.get_list_snapshot_id()
227
 
                if len( snapshot_id ) <= 0:
228
 
                        return
229
 
 
230
 
                combo_index = self.combo_diff.currentIndex()
231
 
                if combo_index < 0:
232
 
                        return
233
 
 
234
 
                snapshot2_id = str( self.combo_diff.itemData( combo_index ).toString() )
235
 
 
236
 
                path1 = self.snapshots.get_snapshot_path_to( snapshot_id, self.path )
237
 
                path2 = self.snapshots.get_snapshot_path_to( snapshot2_id, self.path )
238
 
 
239
 
                #check if the 2 paths are different
240
 
                if path1 == path2:
241
 
                        KMessageBox.error( self, QString.fromUtf8( _('You can\'t compare a snapshot to itself') ) )
242
 
                        return
243
 
 
244
 
                diff_cmd = self.config.get_str_value( 'kde4.diff.cmd', 'kompare' )
245
 
                diff_params = self.config.get_str_value( 'kde4.diff.params', '%1 %2' )
246
 
 
247
 
                if not tools.check_command( diff_cmd ):
248
 
                        KMessageBox.error( self, QString.fromUtf8( _('Command not found: %s') % diff_cmd ) )
249
 
                        return
250
 
 
251
 
                params = diff_params
252
 
                params = params.replace( '%1', "\"%s\"" % path1 )
253
 
                params = params.replace( '%2', "\"%s\"" % path2 )
254
 
 
255
 
                cmd = diff_cmd + ' ' + params + ' &'
256
 
                os.system( cmd  )
257
 
 
258
 
        def on_btn_diff_options_clicked( self ):
259
 
                DiffOptionsDialog( self ).exec_()
260
 
 
261
 
        def accept( self ):
262
 
                snapshot_id = self.get_list_snapshot_id()
263
 
                if len( snapshot_id ) >= 1:
264
 
                        self.snapshot_id = snapshot_id
265
 
                KDialog.accept( self )
266