~tkluck/backintime/mountmonitor

526 by user
reorganize code: common / GNOME / KDE4
1
#    Back In Time
585.1.40 by User
Update authors, copyright ...
2
#    Copyright (C) 2008-2009 Oprea Dan, Bart de Koning, Richard Bailey
526 by user
reorganize code: common / GNOME / KDE4
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 stat
22
import sys
23
24
if len( os.getenv( 'DISPLAY', '' ) ) == 0:
25
	os.putenv( 'DISPLAY', ':0.0' )
26
27
import datetime
28
import gettext
29
import time
30
import threading
31
32
sys.path = [os.path.join( os.path.dirname( os.path.abspath( os.path.dirname( __file__ ) ) ), 'common' )] + sys.path
33
34
import backintime
35
import config
36
import tools
37
import logger
38
import snapshots
39
import guiapplicationinstance
40
41
from PyQt4.QtGui import *
42
from PyQt4.QtCore import *
43
from PyKDE4.kdecore import *
44
from PyKDE4.kdeui import *
45
from PyKDE4.kio import *
46
47
import kde4tools
48
import settingsdialog
49
import snapshotsdialog
50
51
52
_=gettext.gettext
53
54
55
class MainWindow( KMainWindow ):
56
	def __init__( self, config, app_instance, kapp, kaboutdata ):
57
		KMainWindow.__init__( self )
58
59
		self.config = config
60
		self.app_instance = app_instance
61
		self.kapp = kapp
62
		self.kaboutdata = kaboutdata
63
		self.snapshots = snapshots.Snapshots( config )
64
		self.last_take_snapshot_message = None
65
66
		#main toolbar
67
		self.main_toolbar = self.toolBar()
68
		self.main_toolbar.setFloatable( False )
69
585.1.38 by User
Dev profiles
70
		#profiles
71
		#self.main_toolbar.addWidget( QLabel( QString.fromUtf8( _('Profile:') ), self ) )
72
		self.first_update_all = True
73
		self.disable_profile_changed = False
74
		self.combo_profiles = KComboBox( self )
75
		self.combo_profiles_action = self.main_toolbar.addWidget( self.combo_profiles )
76
		#self.combo_profiles.setMinimumWidth( 250 )
77
526 by user
reorganize code: common / GNOME / KDE4
78
		self.btn_take_snapshot = self.main_toolbar.addAction( KIcon( 'document-save' ), '' )
79
		self.btn_take_snapshot.setToolTip( QString.fromUtf8( _('Take snapshot') ) )
552 by user
dev
80
		QObject.connect( self.btn_take_snapshot, SIGNAL('triggered()'), self.on_btn_take_snapshot_clicked )
526 by user
reorganize code: common / GNOME / KDE4
81
82
		self.btn_update_snapshots = self.main_toolbar.addAction( KIcon( 'view-refresh' ), '' )
83
		self.btn_update_snapshots.setToolTip( QString.fromUtf8( _('Update snapshots') ) )
552 by user
dev
84
		QObject.connect( self.btn_update_snapshots, SIGNAL('triggered()'), self.on_btn_update_snapshots_clicked )
526 by user
reorganize code: common / GNOME / KDE4
85
86
		self.btn_name_snapshot = self.main_toolbar.addAction( KIcon( 'edit-rename' ), '' )
87
		self.btn_name_snapshot.setToolTip( QString.fromUtf8( _('Snapshot Name') ) )
552 by user
dev
88
		QObject.connect( self.btn_name_snapshot, SIGNAL('triggered()'), self.on_btn_name_snapshot_clicked )
526 by user
reorganize code: common / GNOME / KDE4
89
90
		self.btn_remove_snapshot = self.main_toolbar.addAction( KIcon( 'edit-delete' ), '' )
91
		self.btn_remove_snapshot.setToolTip( QString.fromUtf8( _('Remove Snapshot') ) )
552 by user
dev
92
		QObject.connect( self.btn_remove_snapshot, SIGNAL('triggered()'), self.on_btn_remove_snapshot_clicked )
526 by user
reorganize code: common / GNOME / KDE4
93
	
94
		self.main_toolbar.addSeparator()
95
96
		self.btn_settings = self.main_toolbar.addAction( KIcon( 'configure' ), '' )
97
		self.btn_settings.setToolTip( QString.fromUtf8( _('Settings') ) )
552 by user
dev
98
		QObject.connect( self.btn_settings, SIGNAL('triggered()'), self.on_btn_settings_clicked )
526 by user
reorganize code: common / GNOME / KDE4
99
100
		self.main_toolbar.addSeparator()
101
102
		self.btn_about = self.main_toolbar.addAction( KIcon( 'help-about' ), '' )
103
		self.btn_about.setToolTip( QString.fromUtf8( _('About') ) )
552 by user
dev
104
		QObject.connect( self.btn_about, SIGNAL('triggered()'), self.on_btn_about_clicked )
526 by user
reorganize code: common / GNOME / KDE4
105
106
		self.btn_help = self.main_toolbar.addAction( KIcon( 'help-contents' ), '' )
107
		self.btn_help.setToolTip( QString.fromUtf8( _('Help') ) )
552 by user
dev
108
		QObject.connect( self.btn_help, SIGNAL('triggered()'), self.on_btn_help_clicked )
526 by user
reorganize code: common / GNOME / KDE4
109
110
		self.main_toolbar.addSeparator()
111
112
		self.btn_quit = self.main_toolbar.addAction( KIcon( 'application-exit' ), '' )
113
		self.btn_quit.setToolTip( QString.fromUtf8( _('Exit') ) )
552 by user
dev
114
		QObject.connect( self.btn_quit, SIGNAL('triggered()'), self.close )
526 by user
reorganize code: common / GNOME / KDE4
115
551 by Dan
dev
116
		self.main_toolbar.addAction( KToolBarSpacerAction( self ) )
117
585.1.29 by User
dev profiles
118
		self.main_toolbar.addSeparator()
119
120
		self.btn_link = self.main_toolbar.addAction( KIcon( 'go-home' ), '' )
121
		self.btn_link.setToolTip( QString.fromUtf8( 'backintime.le-web.org' ) )
122
		QObject.connect( self.btn_link, SIGNAL('triggered()'), self.open_url )
123
		
526 by user
reorganize code: common / GNOME / KDE4
124
		#main splitter
125
		self.main_splitter = QSplitter( self )
126
		self.main_splitter.setOrientation( Qt.Horizontal )
127
128
		#timeline
129
		self.list_time_line = QTreeWidget( self )
130
		self.list_time_line.setRootIsDecorated( False )
131
		self.list_time_line.setEditTriggers( QAbstractItemView.NoEditTriggers )
132
		self.list_time_line.setHeaderLabel( QString.fromUtf8( _('Snapshots') ) )
133
		self.main_splitter.addWidget( self.list_time_line )
134
135
		#right widget
136
		self.right_widget = QGroupBox( self )
137
		self.main_splitter.addWidget( self.right_widget )
138
		right_layout = QVBoxLayout( self.right_widget )
139
		#left, top, right, bottom = right_layout.getContentsMargins()
140
		#right_layout.setContentsMargins( 0, 0, 0, right )
141
142
		#files toolbar
143
		self.files_view_toolbar = KToolBar( self )
144
		self.files_view_toolbar.setFloatable( False )
145
146
		self.btn_folder_up = self.files_view_toolbar.addAction( KIcon( 'go-up' ), '' )
147
		self.btn_folder_up.setToolTip( QString.fromUtf8( _('Up') ) )
552 by user
dev
148
		QObject.connect( self.btn_folder_up, SIGNAL('triggered()'), self.on_btn_folder_up_clicked )
526 by user
reorganize code: common / GNOME / KDE4
149
150
		self.edit_current_path = KLineEdit( self )
151
		self.edit_current_path.setReadOnly( True )
152
		self.files_view_toolbar.addWidget( self.edit_current_path )
153
154
		#show hidden files
155
		self.show_hidden_files = self.config.get_bool_value( 'kde4.show_hidden_files', False )
156
157
		self.btn_show_hidden_files = KToggleAction( KIcon( 'list-add' ), '', self.files_view_toolbar )
158
		self.files_view_toolbar.addAction( self.btn_show_hidden_files )
159
		self.btn_show_hidden_files.setCheckable( True )
160
		self.btn_show_hidden_files.setChecked( self.show_hidden_files )
161
		self.btn_show_hidden_files.setToolTip( QString.fromUtf8( _('Show hidden files') ) )
552 by user
dev
162
		QObject.connect( self.btn_show_hidden_files, SIGNAL('toggled(bool)'), self.on_btn_show_hidden_files_toggled )
526 by user
reorganize code: common / GNOME / KDE4
163
164
		self.files_view_toolbar.addSeparator()
165
166
		self.btn_restore = self.files_view_toolbar.addAction( KIcon( 'document-revert' ), '' )
167
		self.btn_restore.setToolTip( QString.fromUtf8( _('Restore') ) )
552 by user
dev
168
		QObject.connect( self.btn_restore, SIGNAL('triggered()'), self.on_btn_restore_clicked )
526 by user
reorganize code: common / GNOME / KDE4
169
170
		self.btn_copy = self.files_view_toolbar.addAction( KIcon( 'edit-copy' ), '' )
171
		self.btn_copy.setToolTip( QString.fromUtf8( _('Copy') ) )
552 by user
dev
172
		QObject.connect( self.btn_copy, SIGNAL('triggered()'), self.on_btn_copy_to_clipboard_clicked )
526 by user
reorganize code: common / GNOME / KDE4
173
174
		self.btn_snapshots = self.files_view_toolbar.addAction( KIcon( 'view-list-details' ), '' )
175
		self.btn_snapshots.setToolTip( QString.fromUtf8( _('Snapshots') ) )
552 by user
dev
176
		QObject.connect( self.btn_snapshots, SIGNAL('triggered()'), self.on_btn_snapshots_clicked )
526 by user
reorganize code: common / GNOME / KDE4
177
178
		right_layout.addWidget( self.files_view_toolbar )
179
180
		#second spliter
181
		self.second_splitter = QSplitter( self )
182
		self.second_splitter.setOrientation( Qt.Horizontal )
183
		right_layout.addWidget( self.second_splitter )
184
185
		#places
186
		self.list_places = QTreeWidget( self )
187
		self.list_places.setRootIsDecorated( False )
188
		self.list_places.setEditTriggers( QAbstractItemView.NoEditTriggers )
189
		self.list_places.setHeaderLabel( QString.fromUtf8( _('Shortcuts') ) )
190
		self.second_splitter.addWidget( self.list_places )
191
192
		#files view stacked layout
193
		widget = QWidget( self )
194
		self.files_view_layout = QStackedLayout( widget )
195
		self.second_splitter.addWidget( widget )
196
197
		#folder don't exist label
570 by user
add 'expert option': enable/disable nice for cron jobs
198
		self.lbl_folder_dont_exists = QLabel( QString.fromUtf8( _('This folder don\'t exist\nin current snapshot !') ), self )
526 by user
reorganize code: common / GNOME / KDE4
199
		kde4tools.set_font_bold( self.lbl_folder_dont_exists )
200
		self.lbl_folder_dont_exists.setFrameShadow( QFrame.Sunken )
201
		self.lbl_folder_dont_exists.setFrameShape( QFrame.Panel )
202
		self.lbl_folder_dont_exists.setAlignment( Qt.AlignHCenter | Qt.AlignVCenter )
203
		self.files_view_layout.addWidget( self.lbl_folder_dont_exists )
204
205
		#list files view
206
		self.list_files_view = QTreeView( self )
207
		self.files_view_layout.addWidget( self.list_files_view )
208
		self.list_files_view.setRootIsDecorated( False )
209
		self.list_files_view.setAlternatingRowColors( True )
566 by Dan
dev
210
		#self.list_files_view.setAllColumnsShowFocus( True )
526 by user
reorganize code: common / GNOME / KDE4
211
		self.list_files_view.setEditTriggers( QAbstractItemView.NoEditTriggers )
212
		self.list_files_view.setItemsExpandable( False )
213
		self.list_files_view.setDragEnabled( True )
214
		self.list_files_view.setDragDropMode( QAbstractItemView.DragOnly )
215
216
		self.list_files_view.header().setClickable( True )
217
		self.list_files_view.header().setMovable( False )
218
		self.list_files_view.header().setSortIndicatorShown( True )
219
		
220
		self.list_files_view_model = KDirModel( self )
221
		self.list_files_view_model.removeColumns( 3, 2 )
222
		self.list_files_view_model.dirLister().setAutoErrorHandlingEnabled( False, self )
223
		self.list_files_view_model.dirLister().setAutoUpdate( False )
224
		self.list_files_view_model.dirLister().setDelayedMimeTypes( False )
225
		self.list_files_view_model.dirLister().setMainWindow( self )
226
227
		self.list_files_view_sort_filter_proxy = KDirSortFilterProxyModel( self )
228
		self.list_files_view_sort_filter_proxy.setSourceModel( self.list_files_view_model )
229
230
		self.list_files_view.setModel( self.list_files_view_sort_filter_proxy )
231
232
		self.list_files_view_delegate = KFileItemDelegate( self )
233
		self.list_files_view.setItemDelegate( self.list_files_view_delegate )
234
235
		for column_index in xrange( 3, self.list_files_view_model.columnCount() ):
236
			self.list_files_view.hideColumn( column_index )
237
238
		sort_column = self.config.get_int_value( 'kde4.main_window.files_view.sort.column', 0 )
239
		sort_order = self.config.get_bool_value( 'kde4.main_window.files_view.sort.ascending', True )
240
		if sort_order:
241
			sort_order = Qt.AscendingOrder
242
		else:
243
			sort_order = Qt.DescendingOrder
244
245
		self.list_files_view.header().setSortIndicator( sort_column, sort_order )
246
		self.list_files_view_sort_filter_proxy.sort( self.list_files_view.header().sortIndicatorSection(), self.list_files_view.header().sortIndicatorOrder() )
247
		QObject.connect( self.list_files_view.header(), SIGNAL('sortIndicatorChanged(int,Qt::SortOrder)'), self.list_files_view_sort_filter_proxy.sort )
248
249
		self.files_view_layout.setCurrentWidget( self.list_files_view )
250
251
		#
252
		self.setCentralWidget( self.main_splitter )
253
		
254
		self.statusBar().showMessage( QString.fromUtf8( _('Done') ) )
255
256
		self.snapshots_list = []
257
		self.snapshot_id = '/'
258
		self.path = self.config.get_str_value( 'kde4.last_path', '/' )
556 by user
KDE4: python string <=> QString problems
259
		self.edit_current_path.setText( QString.fromUtf8( self.path ) )
526 by user
reorganize code: common / GNOME / KDE4
260
261
		#restore size and position
262
		x = self.config.get_int_value( 'kde4.main_window.x', -1 )
263
		y = self.config.get_int_value( 'kde4.main_window.y', -1 )
264
		if x >= 0 and y >= 0:
265
			self.move( x, y )
266
267
		w = self.config.get_int_value( 'kde4.main_window.width', 800 )
268
		h = self.config.get_int_value( 'kde4.main_window.height', 500 )
269
		self.resize( w, h )
270
271
		main_splitter_left_w = self.config.get_int_value( 'kde4.main_window.main_splitter_left_w', 150 )
272
		main_splitter_right_w = self.config.get_int_value( 'kde4.main_window.main_splitter_right_w', 450 )
273
		sizes = [ main_splitter_left_w, main_splitter_right_w ]
274
		self.main_splitter.setSizes( sizes )
275
		
276
		second_splitter_left_w = self.config.get_int_value( 'kde4.main_window.second_splitter_left_w', 150 )
277
		second_splitter_right_w = self.config.get_int_value( 'kde4.main_window.second_splitter_right_w', 300 )
278
		sizes = [ second_splitter_left_w, second_splitter_right_w ]
279
		self.second_splitter.setSizes( sizes )
280
281
		files_view_name_width = self.config.get_int_value( 'kde4.main_window.files_view.name_width', -1 )
282
		files_view_size_width = self.config.get_int_value( 'kde4.main_window.files_view.size_width', -1 )
283
		files_view_date_width = self.config.get_int_value( 'kde4.main_window.files_view.date_width', -1 )
284
		if files_view_name_width > 0 and files_view_size_width > 0 and files_view_date_width > 0:
285
			self.list_files_view.header().resizeSection( 0, files_view_name_width )
286
			self.list_files_view.header().resizeSection( 1, files_view_size_width )
287
			self.list_files_view.header().resizeSection( 2, files_view_date_width )
288
289
		self.text_validator = QRegExpValidator( QRegExp( '.*' ), self )
290
291
		#
292
		kde4tools.set_font_bold( self.right_widget )
293
294
		#force settingdialog if it is not configured
295
		if not cfg.is_configured():
296
			settingsdialog.SettingsDialog( self ).exec_()
297
298
		if not cfg.is_configured():
299
			return
585.16.12 by Bart de Koning
KDE support
300
	
301
		if self.config.get_update_other_folders() == True:
302
			settingsdialog.SettingsDialog( self ).update_snapshot_location()
303
585.16.7 by Bart de Koning
Profile fix in kde
304
		
305
		profile_id = cfg.get_current_profile()
306
		if not cfg.can_backup( profile_id ):
570 by user
add 'expert option': enable/disable nice for cron jobs
307
			KMessageBox.error( self, QString.fromUtf8( _('Can\'t find snapshots folder.\nIf it is on a removable drive please plug it and then press OK') ) )
526 by user
reorganize code: common / GNOME / KDE4
308
309
		QObject.connect( self.list_files_view_model.dirLister(), SIGNAL('completed()'), self.on_dir_lister_completed )
310
		QObject.connect( self.list_files_view_model.dirLister(), SIGNAL('canceled()'), self.on_dir_lister_completed )
311
312
		#populate lists
585.1.34 by User
dev profiles
313
		self.update_profiles()
314
		QObject.connect( self.combo_profiles, SIGNAL('currentIndexChanged(int)'), self.on_profile_changed )
315
		#self.update_time_line()
316
		#self.update_places()
317
		#self.update_files_view( 0 )
526 by user
reorganize code: common / GNOME / KDE4
318
319
		self.list_files_view.setFocus()
320
321
		self.update_snapshot_actions()
322
323
		QObject.connect( self.list_time_line, SIGNAL('currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)'), self.on_list_time_line_current_item_changed )
324
		QObject.connect( self.list_places, SIGNAL('currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)'), self.on_list_places_current_item_changed )
325
		QObject.connect( self.list_files_view, SIGNAL('activated(const QModelIndex&)'), self.on_list_files_view_item_activated )
326
327
		self.force_wait_lock_counter = 0
328
	
329
		self.timer_raise_application = QTimer( self )
330
		self.timer_raise_application.setInterval( 1000 )
331
		self.timer_raise_application.setSingleShot( False )
332
		QObject.connect( self.timer_raise_application, SIGNAL('timeout()'), self.raise_application )
333
		self.timer_raise_application.start()
334
335
		self.timer_update_take_snapshot = QTimer( self )
336
		self.timer_update_take_snapshot.setInterval( 1000 )
337
		self.timer_update_take_snapshot.setSingleShot( False )
338
		QObject.connect( self.timer_update_take_snapshot, SIGNAL('timeout()'), self.update_take_snapshot )
339
		self.timer_update_take_snapshot.start()
340
341
	def closeEvent( self, event ):
342
		self.config.set_str_value( 'kde4.last_path', self.path )
343
344
		self.config.set_int_value( 'kde4.main_window.x', self.x() )
345
		self.config.set_int_value( 'kde4.main_window.y', self.y() )
346
		self.config.set_int_value( 'kde4.main_window.width', self.width() )
347
		self.config.set_int_value( 'kde4.main_window.height', self.height() )
348
349
		sizes = self.main_splitter.sizes()
350
		self.config.set_int_value( 'kde4.main_window.main_splitter_left_w', sizes[0] )
351
		self.config.set_int_value( 'kde4.main_window.main_splitter_right_w', sizes[1] )
352
	
353
		sizes = self.second_splitter.sizes()
354
		self.config.set_int_value( 'kde4.main_window.second_splitter_left_w', sizes[0] )
355
		self.config.set_int_value( 'kde4.main_window.second_splitter_right_w', sizes[1] )
356
357
		self.config.set_int_value( 'kde4.main_window.files_view.name_width', self.list_files_view.header().sectionSize( 0 ) )
358
		self.config.set_int_value( 'kde4.main_window.files_view.size_width', self.list_files_view.header().sectionSize( 1 ) )
359
		self.config.set_int_value( 'kde4.main_window.files_view.date_width', self.list_files_view.header().sectionSize( 2 ) )
360
361
		self.config.set_bool_value( 'kde4.show_hidden_files', self.show_hidden_files )
362
363
		self.config.set_int_value( 'kde4.main_window.files_view.sort.column', self.list_files_view.header().sortIndicatorSection() )
364
		self.config.set_bool_value( 'kde4.main_window.files_view.sort.ascending', self.list_files_view.header().sortIndicatorOrder() == Qt.AscendingOrder )
365
		
366
		self.config.save()
367
368
		event.accept()
369
585.1.34 by User
dev profiles
370
	def update_profiles( self ):
371
		if self.disable_profile_changed:
372
			return
373
374
		self.disable_profile_changed = True
375
376
		self.combo_profiles.clear()
377
378
		index = 0
379
		profiles = self.config.get_profiles_sorted_by_name()
380
381
		for profile_id in profiles:
382
			if profile_id == self.config.get_current_profile():
383
				index = self.combo_profiles.count()
384
			self.combo_profiles.addItem( QString.fromUtf8( self.config.get_profile_name( profile_id ) ), QVariant( QString.fromUtf8( profile_id ) ) )
385
386
		self.combo_profiles.setCurrentIndex( index )
585.1.38 by User
Dev profiles
387
		self.combo_profiles_action.setVisible( len( profiles ) > 1 )
388
585.1.34 by User
dev profiles
389
		self.update_profile()
390
391
		self.disable_profile_changed = False
392
393
	def update_profile( self ):
394
		self.update_time_line()
395
		self.update_places()
396
		self.update_files_view( 0 )
397
398
	def on_profile_changed( self, index ):
399
		if self.disable_profile_changed:
400
			return
401
402
		profile_id = str( self.combo_profiles.itemData( index ).toString().toUtf8() )
403
		if len( profile_id ) <= 0:
404
			return
405
		
406
		if profile_id != self.config.get_current_profile():
407
			self.config.set_current_profile( profile_id )
408
			self.update_profile()
409
526 by user
reorganize code: common / GNOME / KDE4
410
	def get_default_startup_folder_and_file( self ):
411
		last_path = self.config.get_str_value( 'gnome.last_path', '' )
412
		if len(last_path) > 0 and os.path.isdir(last_path):
413
			return ( last_path, None, False )
414
		return ( '/', None, False )
415
416
	def get_cmd_startup_folder_and_file( self, cmd ):
417
		if cmd is None:
418
			cmd = self.app_instance.raise_cmd
419
420
		if len( cmd ) < 1:
421
			return None
422
423
		path = None
424
		show_snapshots = False
425
426
		for arg in cmd.split( '\n' ):
427
			if len( arg ) < 1:
428
				continue
429
			if arg == '-s' or arg == '--snapshots':
430
				show_snapshots = True
431
				continue
432
			if arg[0] == '-':
433
				continue
434
			if path is None:
435
				path = arg
436
437
		if path is None:
438
			return None
439
440
		if len( path ) < 1:
441
			return None
442
443
		path = os.path.expanduser( path )
444
		path = os.path.abspath( path )
445
446
		if os.path.isdir( path ):
447
			if len( path ) < 1:
448
				show_snapshots = False
449
450
			if show_snapshots:
451
				return ( os.path.dirname( path ), path, True )
452
			else:
453
				return ( path, '', False )
454
455
		if os.path.isfile( path ):
456
			return ( os.path.dirname( path ), path, show_snapshots )
457
458
		return None
459
460
	def get_startup_folder_and_file( self, cmd = None ):
461
		startup_folder = self.get_cmd_startup_folder_and_file( cmd )
462
		if startup_folder is None:
463
			return self.get_default_startup_folder_and_file()
464
		return startup_folder
465
466
	def raise_application( self ):
467
		raise_cmd = self.app_instance.raise_command()
468
		if raise_cmd is None:
469
			return
470
		
471
		print "Raise cmd: " + raise_cmd
472
		self.kapp.alert( self )
473
474
	def update_take_snapshot( self, force_wait_lock = False ):
475
		if force_wait_lock:
476
			self.force_wait_lock_counter = 10
477
		
478
		busy = self.snapshots.is_busy()
479
		if busy:
480
			self.force_wait_lock_counter = 0
481
482
		if self.force_wait_lock_counter > 0:
483
			self.force_wait_lock_counter = self.force_wait_lock_counter - 1
484
485
		fake_busy = busy or self.force_wait_lock_counter > 0
486
487
		if fake_busy:
488
			take_snapshot_message = None
489
490
			if busy:
491
				take_snapshot_message = self.snapshots.get_take_snapshot_message()
492
493
			if take_snapshot_message is None:
494
				take_snapshot_message = ( 0, '...' )
495
496
			if take_snapshot_message != self.last_take_snapshot_message:
497
				self.last_take_snapshot_message = take_snapshot_message
498
				self.statusBar().showMessage( QString.fromUtf8( _('Working:') + ' ' + self.last_take_snapshot_message[1].replace( '\n', ' ' ) ) )
499
500
			if self.btn_take_snapshot.isEnabled():
501
				self.btn_take_snapshot.setEnabled( False )
502
		elif not self.btn_take_snapshot.isEnabled():
503
			self.btn_take_snapshot.setEnabled( True )
504
			
585.17.5 by Bart de Koning
Fixed update time line in KDE
505
			snapshots_list = self.snapshots.get_snapshots_and_other_list()
526 by user
reorganize code: common / GNOME / KDE4
506
507
			if snapshots_list != self.snapshots_list:
508
				self.snapshots_list = snapshots_list
509
				self.update_time_line( False )
510
			 	self.statusBar().showMessage( QString.fromUtf8( _('Done') ) )
511
			else:
512
				self.statusBar().showMessage( QString.fromUtf8( _('Done, no backup needed') ) )
513
514
		if not fake_busy:
515
			self.last_take_snapshot_message = None
516
517
	def on_list_places_current_item_changed( self, item, previous ):
518
		if item is None:
519
			return
520
556 by user
KDE4: python string <=> QString problems
521
		path = str( item.data( 0, Qt.UserRole ).toString().toUtf8() )
526 by user
reorganize code: common / GNOME / KDE4
522
		if len( path ) == 0:
523
			return
524
525
		if path == self.path:
526
			return
527
528
		self.path = path
529
		self.update_files_view( 3 )
530
531
	def add_place( self, name, path, icon ):
532
		item = QTreeWidgetItem()
533
534
		item.setText( 0, name )
535
536
		if len( icon ) > 0:
537
			item.setIcon( 0, KIcon( icon ) )
538
556 by user
KDE4: python string <=> QString problems
539
		item.setData( 0, Qt.UserRole, QVariant( QString.fromUtf8( path ) ) )
526 by user
reorganize code: common / GNOME / KDE4
540
541
		if len( path ) == 0:
542
			item.setFont( 0, kde4tools.get_font_bold( item.font( 0 ) ) )
543
			#item.setFlags( Qt.NoItemFlags )
544
			item.setFlags( Qt.ItemIsEnabled )
545
			item.setBackgroundColor( 0, QColor( 196, 196, 196 ) )
546
547
		self.list_places.addTopLevelItem( item )
548
549
		if path == self.path:
550
			self.list_places.setCurrentItem( item )
551
552
		return item
553
554
	def update_places( self ):
555
		self.list_places.clear()
556
		self.add_place( QString.fromUtf8( _('Global') ), '', '' )
557
		self.add_place( QString.fromUtf8( _('Root') ), '/', 'computer' )
558
		self.add_place( QString.fromUtf8( _('Home') ), os.path.expanduser( '~' ), 'user-home' )
559
560
		#add backup folders
561
		include_folders = self.config.get_include_folders()
562
		if len( include_folders ) > 0:
570 by user
add 'expert option': enable/disable nice for cron jobs
563
			self.add_place( QString.fromUtf8( _('Backup folders') ), '', '' )
526 by user
reorganize code: common / GNOME / KDE4
564
			for folder in include_folders:
545 by Dan
KDE4: fix some texts
565
				self.add_place( QString.fromUtf8(folder[0]), folder[0], 'document-save' )
526 by user
reorganize code: common / GNOME / KDE4
566
567
	def update_snapshot_actions( self ):
568
		enabled = False
569
570
		item = self.list_time_line.currentItem()
571
		if not item is None:
572
			if len( self.time_line_get_snapshot_id( item ) ) > 1:
573
				enabled = True
574
575
		#update remove/name snapshot buttons
576
		self.btn_name_snapshot.setEnabled( enabled )
577
		self.btn_remove_snapshot.setEnabled( enabled )
578
579
	def on_list_time_line_current_item_changed( self, item, previous ):
580
		self.update_snapshot_actions()
581
582
		if item is None:
583
			return
584
585
		snapshot_id = self.time_line_get_snapshot_id( item )
586
		if len( snapshot_id ) == 0:
587
			#self.list_time_line.setCurrentItem( previous )
588
			return
589
590
		if snapshot_id == self.snapshot_id:
591
			return
592
593
		self.snapshot_id = snapshot_id
594
		self.update_files_view( 2 )
595
596
	def time_line_get_snapshot_id( self, item ):
556 by user
KDE4: python string <=> QString problems
597
		return str( item.data( 0, Qt.UserRole ).toString().toUtf8() ) 
526 by user
reorganize code: common / GNOME / KDE4
598
599
	def time_line_update_snapshot_name( self, item ):
600
		snapshot_id = self.time_line_get_snapshot_id( item )
601
		if len( snapshot_id ) > 0:
602
			item.setText( 0, self.snapshots.get_snapshot_display_name( snapshot_id ) )
603
604
	def add_time_line( self, snapshot_name, snapshot_id ):
605
		item = QTreeWidgetItem()
606
		item.setText( 0, snapshot_name )
607
556 by user
KDE4: python string <=> QString problems
608
		item.setData( 0, Qt.UserRole, QVariant( QString.fromUtf8( snapshot_id ) ) )
526 by user
reorganize code: common / GNOME / KDE4
609
610
		if len( snapshot_id ) == 0:
611
			item.setFont( 0, kde4tools.get_font_bold( item.font( 0 ) ) )
612
			#item.setFlags( Qt.NoItemFlags )
613
			item.setFlags( Qt.ItemIsEnabled )
614
			item.setBackgroundColor( 0, QColor( 196, 196, 196 ) )
615
616
		self.list_time_line.addTopLevelItem( item )
617
618
		return item
619
620
	def update_time_line( self, get_snapshots_list = True ):
621
		self.list_time_line.clear()
622
		self.add_time_line( QString.fromUtf8( self.snapshots.get_snapshot_display_name( '/' ) ), '/' )
623
624
		if get_snapshots_list:
585.17.4 by Bart de Koning
Fixed making initializing snapshotsfolders when not moving and KDE shows snapshots in other folders
625
			self.snapshots_list = self.snapshots.get_snapshots_and_other_list() 
526 by user
reorganize code: common / GNOME / KDE4
626
627
		groups = []
628
		now = datetime.date.today()
629
630
		#today
631
		date = now
632
		groups.append( (QString.fromUtf8( _('Today') ), self.snapshots.get_snapshot_id( date ), []) )
633
634
		#yesterday
635
		date = now - datetime.timedelta( days = 1 )
636
		groups.append( (QString.fromUtf8( _('Yesterday') ), self.snapshots.get_snapshot_id( date ), []) )
637
638
		#this week
639
		date = now - datetime.timedelta( days = now.weekday() )
640
		groups.append( (QString.fromUtf8( _('This week') ), self.snapshots.get_snapshot_id( date ), []) )
641
642
		#last week
643
		date = now - datetime.timedelta( days = now.weekday() + 7 )
644
		groups.append( (QString.fromUtf8( _('Last week') ), self.snapshots.get_snapshot_id( date ), []) )
645
646
		#fill groups
647
		for snapshot_id in self.snapshots_list:
648
			found = False
649
650
			for group in groups:
651
				if snapshot_id >= group[1]:
652
					group[2].append( snapshot_id )
653
					found = True
654
					break
655
656
			if not found:
657
				year = int( snapshot_id[ 0 : 4 ] )
658
				month = int( snapshot_id[ 4 : 6 ] )
659
				date = datetime.date( year, month, 1 )
660
661
				group_name = ''
662
				if year == now.year:
663
					group_name = date.strftime( '%B' ).capitalize()
664
				else:
665
					group_name = date.strftime( '%B, %Y' ).capitalize()
666
667
				groups.append( ( QString.fromUtf8( group_name ), self.snapshots.get_snapshot_id( date ), [ snapshot_id ]) )
668
669
		#fill time_line list
670
		for group in groups:
671
			if len( group[2] ) > 0:
672
				self.add_time_line( group[0], '' );
673
				for snapshot_id in group[2]:
674
					list_item = self.add_time_line( self.snapshots.get_snapshot_display_name( snapshot_id ), snapshot_id )
675
					if snapshot_id == self.snapshot_id:
676
						self.list_time_line.setCurrentItem( list_item )
677
678
		if self.list_time_line.currentItem() is None:
679
			self.list_time_line.setCurrentItem( self.list_time_line.topLevelItem( 0 ) )
680
			if self.snapshot_id != '/':
681
				self.snapshot_id = '/'
682
				self.update_files_view( 2 )
683
684
	def on_btn_take_snapshot_clicked( self ):
585.1.21 by user
dev
685
		backintime.take_snapshot_now_async( self.config )
526 by user
reorganize code: common / GNOME / KDE4
686
		self.update_take_snapshot( True )
687
688
	def on_btn_update_snapshots_clicked( self ):
689
		self.update_time_line()
565 by Dan
GNOME & KDE4: refresh snapshots button force files view to update too
690
		self.update_files_view( 2 )
526 by user
reorganize code: common / GNOME / KDE4
691
692
	def on_btn_name_snapshot_clicked( self ):
693
		item = self.list_time_line.currentItem()
694
		if item is None:
695
			return
696
697
		snapshot_id = self.time_line_get_snapshot_id( item )
698
		if len( snapshot_id ) <= 1:
699
			return
700
701
		name = self.snapshots.get_snapshot_name( snapshot_id )
702
703
		ret_val = KInputDialog.getText( QString.fromUtf8( _( 'Snapshot Name' ) ), '', name, self, self.text_validator )
704
		if not ret_val[1]:
705
			return
706
		
556 by user
KDE4: python string <=> QString problems
707
		new_name = str( ret_val[0].toUtf8() ).strip()
526 by user
reorganize code: common / GNOME / KDE4
708
		if name == new_name:
709
			return
710
711
		self.snapshots.set_snapshot_name( snapshot_id, new_name )
712
		self.time_line_update_snapshot_name( item )
713
714
	def on_btn_remove_snapshot_clicked ( self ):
715
		item = self.list_time_line.currentItem()
716
		if item is None:
717
			return
718
719
		snapshot_id = self.time_line_get_snapshot_id( item )
720
		if len( snapshot_id ) <= 1:
721
			return
722
		
723
		if KMessageBox.Yes != KMessageBox.warningYesNo( self, QString.fromUtf8( _('Are you sure you want to remove the snapshot:\n%s') % self.snapshots.get_snapshot_display_name( snapshot_id ) ) ):
724
			return
725
726
		self.snapshots.remove_snapshot( snapshot_id )
727
		self.update_time_line()
728
729
	def on_btn_settings_clicked( self ):
585.1.34 by User
dev profiles
730
		if QDialog.Accepted == settingsdialog.SettingsDialog( self ).exec_():
731
			self.update_profiles()
526 by user
reorganize code: common / GNOME / KDE4
732
733
	def on_btn_about_clicked( self ):
734
		dlg = KAboutApplicationDialog( self.kaboutdata, self )
735
		dlg.exec_()
736
737
	def on_btn_help_clicked( self ):
738
		KRun.runCommand( "khelpcenter help:/backintime", self )
739
552 by user
dev
740
	def open_url( self, url = 'http://backintime.le-web.org' ):
551 by Dan
dev
741
		self.run = KRun( KUrl( url ), self, True )
742
526 by user
reorganize code: common / GNOME / KDE4
743
	def on_btn_show_hidden_files_toggled( self, checked ):
744
		self.show_hidden_files = checked
745
		self.update_files_view( 1 )
746
747
	def on_btn_restore_clicked( self ):
748
		if len( self.snapshot_id ) <= 1:
749
			return
750
556 by user
KDE4: python string <=> QString problems
751
		selected_file = str( self.list_files_view_sort_filter_proxy.data( self.list_files_view.currentIndex() ).toString().toUtf8() )
526 by user
reorganize code: common / GNOME / KDE4
752
		if len( selected_file ) <= 0:
753
			return
754
755
		rel_path = os.path.join( self.path, selected_file )
756
		self.snapshots.restore( self.snapshot_id, rel_path )
757
758
	def on_btn_copy_to_clipboard_clicked( self ):
556 by user
KDE4: python string <=> QString problems
759
		selected_file = str( self.list_files_view_sort_filter_proxy.data( self.list_files_view.currentIndex() ).toString().toUtf8() )
526 by user
reorganize code: common / GNOME / KDE4
760
		if len( selected_file ) <= 0:
761
			return
762
763
		path = self.snapshots.get_snapshot_path_to( self.snapshot_id, os.path.join( self.path, selected_file ) )
764
		kde4tools.clipboard_set_path( self.kapp, path )
765
766
	def on_btn_snapshots_clicked( self ):
556 by user
KDE4: python string <=> QString problems
767
		selected_file = str( self.list_files_view_sort_filter_proxy.data( self.list_files_view.currentIndex() ).toString().toUtf8() )
526 by user
reorganize code: common / GNOME / KDE4
768
		if len( selected_file ) <= 0:
769
			return
770
771
		rel_path = os.path.join( self.path, selected_file )
772
		icon = None
773
		if self.list_files_view_sort_filter_proxy.data( self.list_files_view.currentIndex(), Qt.DecorationRole ).type() == QVariant.Icon:
774
			icon = self.list_files_view_sort_filter_proxy.data( self.list_files_view.currentIndex(), Qt.DecorationRole )
775
776
		dlg = snapshotsdialog.SnapshotsDialog( self, self.snapshot_id, rel_path, icon )
777
		if QDialog.Accepted == dlg.exec_():
778
			if dlg.snapshot_id != self.snapshot_id:
779
				for index in xrange( self.list_time_line.topLevelItemCount() ):
780
					item = self.list_time_line.topLevelItem( index )
781
					snapshot_id = self.time_line_get_snapshot_id( item )
782
					if snapshot_id == dlg.snapshot_id:
783
						self.snapshot_id = dlg.snapshot_id
784
						self.list_time_line.setCurrentItem( item )
785
						self.update_files_view( 2 )
786
						break
787
788
	def on_btn_folder_up_clicked( self ):
789
		if len( self.path ) <= 1:
790
			return
791
792
		path = os.path.dirname( self.path )
793
		if self.path == path:
794
			return
795
796
		self.path = path
797
		self.update_files_view( 0 )
798
799
	def on_list_files_view_item_activated( self, model_index ):
541 by user
KDE4 FilesView/SnapshotsDialog: ctrl-click just select
800
		if self.kapp.keyboardModifiers() and Qt.ControlModifier:
801
			return
802
526 by user
reorganize code: common / GNOME / KDE4
803
		if model_index is None:
804
			return
805
585.9.1 by Bart de Koning
Fixed bug 404652: difficult characters in KDE
806
		rel_path = str( self.list_files_view_sort_filter_proxy.data( model_index ).toString().toAscii() )
526 by user
reorganize code: common / GNOME / KDE4
807
		if len( rel_path ) <= 0:
808
			return
809
810
		rel_path = os.path.join( self.path, rel_path )
811
		full_path = self.snapshots.get_snapshot_path_to( self.snapshot_id, rel_path )
812
585.1.43 by Dan
fix bug: https://bugs.launchpad.net/backintime/+bug/447841
813
		if os.path.exists( full_path ):
814
			if os.path.isdir( full_path ):
815
				self.path = rel_path
816
				self.update_files_view( 0 )
817
			else:
818
				self.run = KRun( KUrl( full_path ), self, True )
526 by user
reorganize code: common / GNOME / KDE4
819
820
	def files_view_get_name( self, item ):
556 by user
KDE4: python string <=> QString problems
821
		return str( item.text( 0 ).toUtf8() )
526 by user
reorganize code: common / GNOME / KDE4
822
823
	def files_view_get_type( self, item ):
824
		return int( item.text( 4 ) )
825
826
	def add_files_view( self, name, size_str, date_str, size_int, type ):
827
		full_path = self.snapshots.get_snapshot_path_to( self.snapshot_id, os.path.join( self.path, name ) )
828
		icon = KIcon( KMimeType.iconNameForUrl( KUrl( full_path ) ) )
829
830
		item = QTreeWidgetItem( self.list_files_view )
831
832
		item.setIcon( 0, icon )
833
		item.setText( 0, name )
834
		item.setText( 1, size_str )
835
		item.setText( 2, date_str )
836
		item.setText( 3, str( size_int ) )
837
		item.setText( 4, str( type ) )
838
839
		self.list_files_view.addTopLevelItem( item )
840
		return item
841
842
	def update_files_view( self, changed_from, selected_file = None, show_snapshots = False ): #0 - files view change directory, 1 - files view, 2 - time_line, 3 - places
843
		if 0 == changed_from or 3 == changed_from:
844
			selected_file = ''
845
846
		if 0 == changed_from:
847
			#update places
848
			self.list_places.setCurrentItem( None )
849
			for place_index in xrange( self.list_places.topLevelItemCount() ):
850
				item = self.list_places.topLevelItem( place_index )
556 by user
KDE4: python string <=> QString problems
851
				if self.path == str( item.data( 0, Qt.UserRole ).toString().toUtf8() ):
526 by user
reorganize code: common / GNOME / KDE4
852
					self.list_places.setCurrentItem( item )
853
					break
854
855
		tooltip = ''
856
		text = ''
857
		if len( self.snapshot_id ) > 1:
858
			name = self.snapshots.get_snapshot_display_id( self.snapshot_id )
859
			text = _('Snapshot: %s') % name
860
			tooltip = _('View the snapshot made at %s') % name
861
		else:
862
			tooltip = _('View the current disk content')
863
			text = _('Now')
864
865
		self.right_widget.setTitle( QString.fromUtf8( _( text ) ) )
866
		self.right_widget.setToolTip( QString.fromUtf8( _( tooltip ) ) )
867
868
		#try to keep old selected file
869
		if selected_file is None:
556 by user
KDE4: python string <=> QString problems
870
			selected_file = str( self.list_files_view_sort_filter_proxy.data( self.list_files_view.currentIndex() ).toString().toUtf8() )
526 by user
reorganize code: common / GNOME / KDE4
871
872
		self.selected_file = selected_file
873
	
874
		#update files view
875
		full_path = self.snapshots.get_snapshot_path_to( self.snapshot_id, self.path )
876
877
		if os.path.isdir( full_path ):
878
			self.list_files_view_model.dirLister().setShowingDotFiles( self.show_hidden_files )
565 by Dan
GNOME & KDE4: refresh snapshots button force files view to update too
879
			self.list_files_view_model.dirLister().openUrl( KUrl( QString.fromUtf8( full_path ) ), KDirLister.Reload )
526 by user
reorganize code: common / GNOME / KDE4
880
			self.files_view_toolbar.setEnabled( False )
881
			self.files_view_layout.setCurrentWidget( self.list_files_view )
882
		else:
883
			self.btn_restore.setEnabled( False )
884
			self.btn_copy.setEnabled( False )
885
			self.btn_snapshots.setEnabled( False )
886
			self.files_view_layout.setCurrentWidget( self.lbl_folder_dont_exists )
887
888
		#show current path
556 by user
KDE4: python string <=> QString problems
889
		self.edit_current_path.setText( QString.fromUtf8( self.path ) )
526 by user
reorganize code: common / GNOME / KDE4
890
891
		#update folder_up button state
892
		self.btn_folder_up.setEnabled( len( self.path ) > 1 )
893
894
#		#show snapshots
895
#		if show_snapshots:
896
#			self.on_btn_snapshots_clicked( None )
897
898
	def on_dir_lister_completed( self ):
899
		has_files = ( self.list_files_view_model.rowCount() > 0 )
900
901
		#update restore button state
902
		self.btn_restore.setEnabled( len( self.snapshot_id ) > 1 and has_files )
903
904
		#update copy button state
905
		self.btn_copy.setEnabled( has_files )
906
907
		#update snapshots button state
908
		self.btn_snapshots.setEnabled( has_files )
909
910
		#enable files toolbar
911
		self.files_view_toolbar.setEnabled( True )
912
913
		#select selected_file
914
		found = False
915
916
		if len( self.selected_file ) > 0:
917
			for index in xrange( self.list_files_view_sort_filter_proxy.rowCount() ):
918
				model_index = self.list_files_view_sort_filter_proxy.index( index, 0 )
556 by user
KDE4: python string <=> QString problems
919
				file_name = str( self.list_files_view_sort_filter_proxy.data( model_index ).toString().toUtf8() )
526 by user
reorganize code: common / GNOME / KDE4
920
				if file_name == self.selected_file:
921
					self.list_files_view.setCurrentIndex( model_index )
922
					found = True
923
					break
924
			self.selected_file = ''
925
926
		if not found and has_files:
927
			self.list_files_view.setCurrentIndex( self.list_files_view_sort_filter_proxy.index( 0, 0 ) )
928
929
930
class KDE4TakeSnapshotCallback( threading.Thread ): #used to display status icon
931
	def __init__( self ):
932
		threading.Thread.__init__( self )
933
		self.stop_flag = False
934
		self.cfg = None
935
936
	def init( self, cfg ):
937
		self.cfg = cfg
938
		self.snapshots = snapshots.Snapshots( self.cfg )
939
940
	def snapshot_begin( self ):
941
		self.stop_flag = False
942
		self.start()
943
944
	def snapshot_end( self ):
945
		self.stop_flag = True
946
		try:
947
			self.join()
948
		except:
949
			pass
950
951
	def show_popup( self ):
952
		if not self.popup is None:
953
			self.popup.deleteLater()
954
			self.popup = None
955
956
		if not self.last_message is None:
957
			self.popup = KPassivePopup.message( self.cfg.APP_NAME, QString.fromUtf8( self.last_message[1] ), self.status_icon )
958
			self.popup.setAutoDelete( False )
959
960
	def run(self):
961
		logger.info( '[KDE4TakeSnapshotCallback.run]' )
962
963
		if not check_x_server():
964
			logger.info( '[KDE4TakeSnapshotCallback.run] no X server' )
965
			return
966
967
		logger.info( '[KDE4TakeSnapshotCallback.run] begin loop' )
968
969
		kapp, kaboutdata = create_kapplication( self.cfg )
970
		self.last_message = None
971
972
		self.status_icon = KSystemTrayIcon()
973
		self.status_icon.setIcon( KIcon('document-save') )
974
		#self.status_icon.actionCollection().clear()
975
		self.status_icon.setContextMenu( None )
976
		self.status_icon.show()
977
		self.popup = None
978
		QObject.connect( self.status_icon, SIGNAL('activated(QSystemTrayIcon::ActivationReason)'), self.show_popup )
979
		first_error = self.cfg.is_notify_enabled()
980
981
		while True:
982
			kapp.processEvents()
983
		
984
			if self.stop_flag:
985
				break
986
987
			if not kapp.hasPendingEvents():
988
				message = self.snapshots.get_take_snapshot_message()
989
				if message is None and self.last_message is None:
990
					message = ( 0, _('Working...') )
991
992
				if not message is None:
993
					if message != self.last_message:
994
						self.last_message = message
995
						self.status_icon.setToolTip( QString.fromUtf8( self.last_message[1] ) )
996
997
						if self.last_message[0] != 0:
998
							self.status_icon.setIcon( KIcon('document-save-as') )
999
							if first_error:
1000
								first_error = False
1001
								self.show_popup()
1002
						else:
1003
							self.status_icon.setIcon( KIcon('document-save') )
1004
1005
				time.sleep( 0.2 )
1006
		
1007
		self.status_icon.hide()
1008
		kapp.processEvents()
1009
		
1010
		logger.info( '[KDE4TakeSnapshotCallback.run] end loop' )
1011
1012
1013
def create_kapplication( cfg ):
585.1.40 by User
Update authors, copyright ...
1014
	kaboutdata = KAboutData( 'backintime', '', ki18n( cfg.APP_NAME ), cfg.VERSION, ki18n( '' ), KAboutData.License_GPL_V2, ki18n( cfg.COPYRIGHT ), ki18n( '' ), 'http://backintime.le-web.org', 'bit-team@lists.launchpad.net' )
526 by user
reorganize code: common / GNOME / KDE4
1015
	kaboutdata.setProgramIconName( 'document-save' )
1016
577 by Dan
dev
1017
	#extra_translations = _('about-translators')
1018
	#if extra_translations is None:
1019
	#	extra_translations = ''
1020
	#elif extra_translations == 'about-translators':
1021
	#	extra_translations = ''
1022
	#
1023
	#translation_text = cfg.get_translations() + extra_translations
1024
	translation_text = cfg.get_translations()
1025
	
526 by user
reorganize code: common / GNOME / KDE4
1026
	translators = []
1027
	translator_emails = []
1028
	for line in translation_text.split( '\n' ):
1029
		line = line.strip()
1030
		if len( line ) == 0:
1031
			continue
1032
		
1033
		index1 = line.find( ':' )
1034
		if index1 < 0:
1035
			continue
1036
1037
		index2 = line.find( '<', index1 )
1038
		if index2 < 0:
1039
			continue
1040
1041
		index3 = line.find( '>', index2 )
1042
		if index3 < 0:
1043
			continue
1044
1045
		translators.append( line[ index1 + 1 : index2 ].strip() )
1046
		translator_emails.append( line[ index2 + 1 : index3 ].strip() )
1047
1048
	kaboutdata.setTranslator( ki18n( ','.join( translators ) ), ki18n( ','.join( translator_emails ) ) )
1049
1050
	#KCmdLineArgs.init( sys.argv, kaboutdata )
1051
	KCmdLineArgs.init( [sys.argv[0]], kaboutdata )
1052
	return ( KApplication(), kaboutdata )
1053
1054
1055
if __name__ == '__main__':
1056
	cfg = backintime.start_app( 'backintime-kde4' )
1057
1058
	raise_cmd = ''
1059
	if len( sys.argv ) > 1:
1060
		raise_cmd = '\n'.join( sys.argv[ 1 : ] )
1061
1062
	app_instance = guiapplicationinstance.GUIApplicationInstance( cfg.get_app_instance_file(), raise_cmd )
1063
1064
	logger.openlog()
1065
	kapp, kaboutdata = create_kapplication( cfg )
1066
1067
	main_window = MainWindow( cfg, app_instance, kapp, kaboutdata )
1068
1069
	if cfg.is_configured():
1070
		main_window.show()
1071
		kapp.exec_()
1072
1073
	logger.closelog()
1074
1075
	app_instance.exit_application()
1076