2
# Copyright (C) 2008-2009 Oprea Dan
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.
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.
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.
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 *
39
class DiffOptionsDialog( KDialog ):
40
def __init__( self, parent ):
41
KDialog.__init__( self, parent )
42
self.config = parent.config
44
self.setWindowIcon( KIcon( 'configure' ) )
45
self.setCaption( QString.fromUtf8( _( 'Diff Options' ) ) )
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 )
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' )
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 )
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 )
63
self.main_layout.addWidget( QLabel( QString.fromUtf8( _( 'Use %1 and %2 for path parameters' ) ) ), 2, 1 )
66
diff_cmd = str( self.edit_command.text() )
67
diff_params = str( self.edit_params.text() )
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 )
74
KDialog.accept( self )
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
85
self.snapshot_id = snapshot_id
89
self.setWindowIcon( KIcon( 'view-list-details' ) )
90
self.setCaption( QString.fromUtf8( _( 'Snapshots' ) ) )
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 )
99
self.edit_path = KLineEdit( self.path, self )
100
self.edit_path.setReadOnly( True )
101
self.main_layout.addWidget( self.edit_path )
104
self.toolbar = KToolBar( self )
105
self.toolbar.setFloatable( False )
106
self.main_layout.addWidget( self.toolbar )
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 )
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 )
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 )
125
layout = QHBoxLayout()
126
self.main_layout.addLayout( layout )
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 )
132
self.combo_diff = KComboBox( self )
133
layout.addWidget( self.combo_diff, 2 )
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') ) )
140
QObject.connect( self, SIGNAL('user1Clicked()'), self.on_btn_diff_options_clicked )
142
self.setDefaultButton( KDialog.Ok )
144
#update list and combobox
145
self.update_snapshots()
147
def add_snapshot_( self, snapshot_id, is_dir ):
148
full_path = self.snapshots.get_snapshot_path_to( snapshot_id, self.path )
150
if not os.path.exists( full_path ):
153
if is_dir != os.path.isdir( full_path ):
156
name = self.snapshots.get_snapshot_display_name( snapshot_id )
159
item = QListWidgetItem( QString.fromUtf8( name ), self.list_snapshots )
160
item.setData( Qt.UserRole, QVariant( snapshot_id ) )
162
if self.list_snapshots.currentItem() is None:
163
self.list_snapshots.setCurrentItem( item )
166
self.combo_diff.addItem( QString.fromUtf8( name ), QVariant( snapshot_id ) )
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 )
173
def update_snapshots( self ):
174
self.list_snapshots.clear()
175
self.combo_diff.clear()
177
path = self.snapshots.get_snapshot_path_to( self.snapshot_id, self.path )
178
is_dir = os.path.isdir( path )
181
self.add_snapshot_( '/', is_dir )
184
for snapshot_id in self.snapshots_list:
185
self.add_snapshot_( snapshot_id, is_dir )
187
self.update_toolbar()
189
def get_list_snapshot_id( self ):
190
item = self.list_snapshots.currentItem()
193
return str( item.data( Qt.UserRole ).toString() )
195
def update_toolbar( self ):
196
snapshot_id = self.get_list_snapshot_id()
198
self.btn_copy.setEnabled( len( snapshot_id ) > 0 )
199
self.btn_restore.setEnabled( len( snapshot_id ) > 1 )
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 )
206
def on_btn_copy_to_clipboard_clicked( self ):
207
snapshot_id = self.get_list_snapshot_id()
208
if len( snapshot_id ) < 1:
211
path = self.snapshots.get_snapshot_path_to( snapshot_id, self.path )
212
kde4tools.clipboard_set_path( self.kapp, path )
214
def on_list_snapshots_changed( self ):
215
self.update_toolbar()
217
def on_list_snapshots_executed( self, item ):
218
snapshot_id = self.get_list_snapshot_id()
219
if len( snapshot_id ) <= 0:
222
full_path = self.snapshots.get_snapshot_path_to( snapshot_id, self.path )
223
self.run = KRun( KUrl( full_path ), self, True )
225
def on_btn_diff_clicked( self ):
226
snapshot_id = self.get_list_snapshot_id()
227
if len( snapshot_id ) <= 0:
230
combo_index = self.combo_diff.currentIndex()
234
snapshot2_id = str( self.combo_diff.itemData( combo_index ).toString() )
236
path1 = self.snapshots.get_snapshot_path_to( snapshot_id, self.path )
237
path2 = self.snapshots.get_snapshot_path_to( snapshot2_id, self.path )
239
#check if the 2 paths are different
241
KMessageBox.error( self, QString.fromUtf8( _('You can\'t compare a snapshot to itself') ) )
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' )
247
if not tools.check_command( diff_cmd ):
248
KMessageBox.error( self, QString.fromUtf8( _('Command not found: %s') % diff_cmd ) )
252
params = params.replace( '%1', "\"%s\"" % path1 )
253
params = params.replace( '%2', "\"%s\"" % path2 )
255
cmd = diff_cmd + ' ' + params + ' &'
258
def on_btn_diff_options_clicked( self ):
259
DiffOptionsDialog( self ).exec_()
262
snapshot_id = self.get_list_snapshot_id()
263
if len( snapshot_id ) >= 1:
264
self.snapshot_id = snapshot_id
265
KDialog.accept( self )