def __init__( self, config, app_instance, kapp, kaboutdata ):
		KMainWindow.__init__( self )

		self.config = config
		self.app_instance = app_instance
		self.kapp = kapp
		self.kaboutdata = kaboutdata
		self.snapshots = snapshots.Snapshots( config )
		self.last_take_snapshot_message = None

		#main toolbar
		self.main_toolbar = self.toolBar()
		self.main_toolbar.setFloatable( False )

		self.btn_take_snapshot = self.main_toolbar.addAction( KIcon( 'document-save' ), '' )
		self.btn_take_snapshot.setToolTip( QString.fromUtf8( _('Take snapshot') ) )

		self.btn_update_snapshots = self.main_toolbar.addAction( KIcon( 'view-refresh' ), '' )
		self.btn_update_snapshots.setToolTip( QString.fromUtf8( _('Update snapshots') ) )

		self.btn_name_snapshot = self.main_toolbar.addAction( KIcon( 'edit-rename' ), '' )
		self.btn_name_snapshot.setToolTip( QString.fromUtf8( _('Snapshot Name') ) )

		self.btn_remove_snapshot = self.main_toolbar.addAction( KIcon( 'edit-delete' ), '' )
		self.btn_remove_snapshot.setToolTip( QString.fromUtf8( _('Remove Snapshot') ) )
	
		self.main_toolbar.addSeparator()

		self.btn_settings = self.main_toolbar.addAction( KIcon( 'configure' ), '' )
		self.btn_settings.setToolTip( QString.fromUtf8( _('Settings') ) )

		self.main_toolbar.addSeparator()

		self.btn_about = self.main_toolbar.addAction( KIcon( 'help-about' ), '' )
		self.btn_about.setToolTip( QString.fromUtf8( _('About') ) )

		self.btn_help = self.main_toolbar.addAction( KIcon( 'help-contents' ), '' )
		self.btn_help.setToolTip( QString.fromUtf8( _('Help') ) )

		self.main_toolbar.addSeparator()

		self.btn_quit = self.main_toolbar.addAction( KIcon( 'application-exit' ), '' )
		self.btn_quit.setToolTip( QString.fromUtf8( _('Exit') ) )

		#main splitter
		self.main_splitter = QSplitter( self )
		self.main_splitter.setOrientation( Qt.Horizontal )

		#timeline
		self.list_time_line = QTreeWidget( self )
		self.list_time_line.setRootIsDecorated( False )
		self.list_time_line.setEditTriggers( QAbstractItemView.NoEditTriggers )
		self.list_time_line.setHeaderLabel( QString.fromUtf8( _('Snapshots') ) )
		self.main_splitter.addWidget( self.list_time_line )

		#right widget
		self.right_widget = QGroupBox( self )
		self.main_splitter.addWidget( self.right_widget )
		right_layout = QVBoxLayout( self.right_widget )
		#left, top, right, bottom = right_layout.getContentsMargins()
		#right_layout.setContentsMargins( 0, 0, 0, right )

		#files toolbar
		self.files_view_toolbar = KToolBar( self )
		self.files_view_toolbar.setFloatable( False )

		self.btn_folder_up = self.files_view_toolbar.addAction( KIcon( 'go-up' ), '' )
		self.btn_folder_up.setToolTip( QString.fromUtf8( _('Up') ) )

		self.edit_current_path = KLineEdit( self )
		self.edit_current_path.setReadOnly( True )
		self.files_view_toolbar.addWidget( self.edit_current_path )

		#show hidden files
		self.show_hidden_files = self.config.get_bool_value( 'kde4.show_hidden_files', False )

		self.btn_show_hidden_files = KToggleAction( KIcon( 'list-add' ), '', self.files_view_toolbar )
		self.files_view_toolbar.addAction( self.btn_show_hidden_files )
		self.btn_show_hidden_files.setCheckable( True )
		self.btn_show_hidden_files.setChecked( self.show_hidden_files )
		self.btn_show_hidden_files.setToolTip( QString.fromUtf8( _('Show hidden files') ) )

		self.files_view_toolbar.addSeparator()

		self.btn_restore = self.files_view_toolbar.addAction( KIcon( 'document-revert' ), '' )
		self.btn_restore.setToolTip( QString.fromUtf8( _('Restore') ) )

		self.btn_copy = self.files_view_toolbar.addAction( KIcon( 'edit-copy' ), '' )
		self.btn_copy.setToolTip( QString.fromUtf8( _('Copy') ) )

		self.btn_snapshots = self.files_view_toolbar.addAction( KIcon( 'view-list-details' ), '' )
		self.btn_snapshots.setToolTip( QString.fromUtf8( _('Snapshots') ) )

		right_layout.addWidget( self.files_view_toolbar )

		#second spliter
		self.second_splitter = QSplitter( self )
		self.second_splitter.setOrientation( Qt.Horizontal )
		right_layout.addWidget( self.second_splitter )

		#places
		self.list_places = QTreeWidget( self )
		self.list_places.setRootIsDecorated( False )
		self.list_places.setEditTriggers( QAbstractItemView.NoEditTriggers )
		self.list_places.setHeaderLabel( QString.fromUtf8( _('Shortcuts') ) )
		self.second_splitter.addWidget( self.list_places )

		#files view stacked layout
		widget = QWidget( self )
		self.files_view_layout = QStackedLayout( widget )
		self.second_splitter.addWidget( widget )

		#folder don't exist label
		self.lbl_folder_dont_exists = QLabel( QString.fromUtf8( _('This directory don\'t exist\nin current snapshot !') ), self )
		kde4tools.set_font_bold( self.lbl_folder_dont_exists )
		self.lbl_folder_dont_exists.setFrameShadow( QFrame.Sunken )
		self.lbl_folder_dont_exists.setFrameShape( QFrame.Panel )
		self.lbl_folder_dont_exists.setAlignment( Qt.AlignHCenter | Qt.AlignVCenter )
		self.files_view_layout.addWidget( self.lbl_folder_dont_exists )

		#list files view
		self.list_files_view = QTreeView( self )
		self.files_view_layout.addWidget( self.list_files_view )
		self.list_files_view.setRootIsDecorated( False )
		self.list_files_view.setAlternatingRowColors( True )
		self.list_files_view.setAllColumnsShowFocus( True )
		self.list_files_view.setEditTriggers( QAbstractItemView.NoEditTriggers )
		self.list_files_view.setItemsExpandable( False )
		self.list_files_view.setDragEnabled( True )
		self.list_files_view.setDragDropMode( QAbstractItemView.DragOnly )

		self.list_files_view.header().setClickable( True )
		self.list_files_view.header().setMovable( False )
		self.list_files_view.header().setSortIndicatorShown( True )
		
		self.list_files_view_model = KDirModel( self )
		self.list_files_view_model.removeColumns( 3, 2 )
		self.list_files_view_model.dirLister().setAutoErrorHandlingEnabled( False, self )
		self.list_files_view_model.dirLister().setAutoUpdate( False )
		self.list_files_view_model.dirLister().setDelayedMimeTypes( False )
		self.list_files_view_model.dirLister().setMainWindow( self )

		self.list_files_view_sort_filter_proxy = KDirSortFilterProxyModel( self )
		self.list_files_view_sort_filter_proxy.setSourceModel( self.list_files_view_model )

		self.list_files_view.setModel( self.list_files_view_sort_filter_proxy )

		self.list_files_view_delegate = KFileItemDelegate( self )
		self.list_files_view.setItemDelegate( self.list_files_view_delegate )

		for column_index in xrange( 3, self.list_files_view_model.columnCount() ):
			self.list_files_view.hideColumn( column_index )

		sort_column = self.config.get_int_value( 'kde4.main_window.files_view.sort.column', 0 )
		sort_order = self.config.get_bool_value( 'kde4.main_window.files_view.sort.ascending', True )
		if sort_order:
			sort_order = Qt.AscendingOrder
		else:
			sort_order = Qt.DescendingOrder

		self.list_files_view.header().setSortIndicator( sort_column, sort_order )
		self.list_files_view_sort_filter_proxy.sort( self.list_files_view.header().sortIndicatorSection(), self.list_files_view.header().sortIndicatorOrder() )
		QObject.connect( self.list_files_view.header(), SIGNAL('sortIndicatorChanged(int,Qt::SortOrder)'), self.list_files_view_sort_filter_proxy.sort )

		self.files_view_layout.setCurrentWidget( self.list_files_view )

		#
		self.setCentralWidget( self.main_splitter )
		
		self.statusBar().showMessage( QString.fromUtf8( _('Done') ) )

		self.snapshots_list = []
		self.snapshot_id = '/'
		self.path = self.config.get_str_value( 'kde4.last_path', '/' )
		self.edit_current_path.setText( self.path )

		#restore size and position
		x = self.config.get_int_value( 'kde4.main_window.x', -1 )
		y = self.config.get_int_value( 'kde4.main_window.y', -1 )
		if x >= 0 and y >= 0:
			self.move( x, y )

		w = self.config.get_int_value( 'kde4.main_window.width', 800 )
		h = self.config.get_int_value( 'kde4.main_window.height', 500 )
		self.resize( w, h )

		main_splitter_left_w = self.config.get_int_value( 'kde4.main_window.main_splitter_left_w', 150 )
		main_splitter_right_w = self.config.get_int_value( 'kde4.main_window.main_splitter_right_w', 450 )
		sizes = [ main_splitter_left_w, main_splitter_right_w ]
		self.main_splitter.setSizes( sizes )
		
		second_splitter_left_w = self.config.get_int_value( 'kde4.main_window.second_splitter_left_w', 150 )
		second_splitter_right_w = self.config.get_int_value( 'kde4.main_window.second_splitter_right_w', 300 )
		sizes = [ second_splitter_left_w, second_splitter_right_w ]
		self.second_splitter.setSizes( sizes )

		files_view_name_width = self.config.get_int_value( 'kde4.main_window.files_view.name_width', -1 )
		files_view_size_width = self.config.get_int_value( 'kde4.main_window.files_view.size_width', -1 )
		files_view_date_width = self.config.get_int_value( 'kde4.main_window.files_view.date_width', -1 )
		if files_view_name_width > 0 and files_view_size_width > 0 and files_view_date_width > 0:
			self.list_files_view.header().resizeSection( 0, files_view_name_width )
			self.list_files_view.header().resizeSection( 1, files_view_size_width )
			self.list_files_view.header().resizeSection( 2, files_view_date_width )

		self.text_validator = QRegExpValidator( QRegExp( '.*' ), self )

		#
		kde4tools.set_font_bold( self.right_widget )

		#force settingdialog if it is not configured
		if not cfg.is_configured():
			kde4settingsdialog.SettingsDialog( self ).exec_()

		if not cfg.is_configured():
			return

		if not cfg.can_backup():
			KMessageBox.error( self, QString.fromUtf8( _('Can\'t find snapshots directory.\nIf it is on a removable drive please plug it and then press OK') ) )

		QObject.connect( self.list_files_view_model.dirLister(), SIGNAL('completed()'), self.on_dir_lister_completed )
		QObject.connect( self.list_files_view_model.dirLister(), SIGNAL('canceled()'), self.on_dir_lister_completed )

		#populate lists
		self.update_time_line()
		self.update_places()
		self.update_files_view( 0 )

		self.list_files_view.setFocus()

		self.update_snapshot_actions()

		QObject.connect( self.list_time_line, SIGNAL('currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)'), self.on_list_time_line_current_item_changed )
		QObject.connect( self.list_places, SIGNAL('currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)'), self.on_list_places_current_item_changed )
		QObject.connect( self.list_files_view, SIGNAL('activated(const QModelIndex&)'), self.on_list_files_view_item_activated )

		QObject.connect( self.btn_take_snapshot, SIGNAL('triggered()'), self.on_btn_take_snapshot_clicked )
		QObject.connect( self.btn_update_snapshots, SIGNAL('triggered()'), self.on_btn_update_snapshots_clicked )
		QObject.connect( self.btn_name_snapshot, SIGNAL('triggered()'), self.on_btn_name_snapshot_clicked )
		QObject.connect( self.btn_remove_snapshot, SIGNAL('triggered()'), self.on_btn_remove_snapshot_clicked )
		QObject.connect( self.btn_settings, SIGNAL('triggered()'), self.on_btn_settings_clicked )
		QObject.connect( self.btn_about, SIGNAL('triggered()'), self.on_btn_about_clicked )
		QObject.connect( self.btn_help, SIGNAL('triggered()'), self.on_btn_help_clicked )
		QObject.connect( self.btn_quit, SIGNAL('triggered()'), self.close )
		QObject.connect( self.btn_folder_up, SIGNAL('triggered()'), self.on_btn_folder_up_clicked )
		QObject.connect( self.btn_show_hidden_files, SIGNAL('toggled(bool)'), self.on_btn_show_hidden_files_toggled )
		QObject.connect( self.btn_restore, SIGNAL('triggered()'), self.on_btn_restore_clicked )
		QObject.connect( self.btn_copy, SIGNAL('triggered()'), self.on_btn_copy_to_clipboard_clicked )
		QObject.connect( self.btn_snapshots, SIGNAL('triggered()'), self.on_btn_snapshots_clicked )

		self.force_wait_lock_counter = 0
	
		self.timer_raise_application = QTimer( self )
		self.timer_raise_application.setInterval( 1000 )
		self.timer_raise_application.setSingleShot( False )
		QObject.connect( self.timer_raise_application, SIGNAL('timeout()'), self.raise_application )
		self.timer_raise_application.start()

		self.timer_update_take_snapshot = QTimer( self )
		self.timer_update_take_snapshot.setInterval( 1000 )
		self.timer_update_take_snapshot.setSingleShot( False )
		QObject.connect( self.timer_update_take_snapshot, SIGNAL('timeout()'), self.update_take_snapshot )
		self.timer_update_take_snapshot.start()
Ejemplo n.º 2
0
    def __init__(self, config, app_instance, kapp, kaboutdata):
        KMainWindow.__init__(self)

        self.config = config
        self.app_instance = app_instance
        self.kapp = kapp
        self.kaboutdata = kaboutdata
        self.snapshots = snapshots.Snapshots(config)
        self.last_take_snapshot_message = None

        #main toolbar
        self.main_toolbar = self.toolBar()
        self.main_toolbar.setFloatable(False)

        self.btn_take_snapshot = self.main_toolbar.addAction(
            KIcon('document-save'), '')
        self.btn_take_snapshot.setToolTip(QString.fromUtf8(_('Take snapshot')))

        self.btn_update_snapshots = self.main_toolbar.addAction(
            KIcon('view-refresh'), '')
        self.btn_update_snapshots.setToolTip(
            QString.fromUtf8(_('Update snapshots')))

        self.btn_name_snapshot = self.main_toolbar.addAction(
            KIcon('edit-rename'), '')
        self.btn_name_snapshot.setToolTip(QString.fromUtf8(_('Snapshot Name')))

        self.btn_remove_snapshot = self.main_toolbar.addAction(
            KIcon('edit-delete'), '')
        self.btn_remove_snapshot.setToolTip(
            QString.fromUtf8(_('Remove Snapshot')))

        self.main_toolbar.addSeparator()

        self.btn_settings = self.main_toolbar.addAction(KIcon('configure'), '')
        self.btn_settings.setToolTip(QString.fromUtf8(_('Settings')))

        self.main_toolbar.addSeparator()

        self.btn_about = self.main_toolbar.addAction(KIcon('help-about'), '')
        self.btn_about.setToolTip(QString.fromUtf8(_('About')))

        self.btn_help = self.main_toolbar.addAction(KIcon('help-contents'), '')
        self.btn_help.setToolTip(QString.fromUtf8(_('Help')))

        self.main_toolbar.addSeparator()

        self.btn_quit = self.main_toolbar.addAction(KIcon('application-exit'),
                                                    '')
        self.btn_quit.setToolTip(QString.fromUtf8(_('Exit')))

        #main splitter
        self.main_splitter = QSplitter(self)
        self.main_splitter.setOrientation(Qt.Horizontal)

        #timeline
        self.list_time_line = QTreeWidget(self)
        self.list_time_line.setRootIsDecorated(False)
        self.list_time_line.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.list_time_line.setHeaderLabel(QString.fromUtf8(_('Snapshots')))
        self.main_splitter.addWidget(self.list_time_line)

        #right widget
        self.right_widget = QGroupBox(self)
        self.main_splitter.addWidget(self.right_widget)
        right_layout = QVBoxLayout(self.right_widget)
        #left, top, right, bottom = right_layout.getContentsMargins()
        #right_layout.setContentsMargins( 0, 0, 0, right )

        #files toolbar
        self.files_view_toolbar = KToolBar(self)
        self.files_view_toolbar.setFloatable(False)

        self.btn_folder_up = self.files_view_toolbar.addAction(
            KIcon('go-up'), '')
        self.btn_folder_up.setToolTip(QString.fromUtf8(_('Up')))

        self.edit_current_path = KLineEdit(self)
        self.edit_current_path.setReadOnly(True)
        self.files_view_toolbar.addWidget(self.edit_current_path)

        #show hidden files
        self.show_hidden_files = self.config.get_bool_value(
            'kde4.show_hidden_files', False)

        self.btn_show_hidden_files = KToggleAction(KIcon('list-add'), '',
                                                   self.files_view_toolbar)
        self.files_view_toolbar.addAction(self.btn_show_hidden_files)
        self.btn_show_hidden_files.setCheckable(True)
        self.btn_show_hidden_files.setChecked(self.show_hidden_files)
        self.btn_show_hidden_files.setToolTip(
            QString.fromUtf8(_('Show hidden files')))

        self.files_view_toolbar.addSeparator()

        self.btn_restore = self.files_view_toolbar.addAction(
            KIcon('document-revert'), '')
        self.btn_restore.setToolTip(QString.fromUtf8(_('Restore')))

        self.btn_copy = self.files_view_toolbar.addAction(
            KIcon('edit-copy'), '')
        self.btn_copy.setToolTip(QString.fromUtf8(_('Copy')))

        self.btn_snapshots = self.files_view_toolbar.addAction(
            KIcon('view-list-details'), '')
        self.btn_snapshots.setToolTip(QString.fromUtf8(_('Snapshots')))

        right_layout.addWidget(self.files_view_toolbar)

        #second spliter
        self.second_splitter = QSplitter(self)
        self.second_splitter.setOrientation(Qt.Horizontal)
        right_layout.addWidget(self.second_splitter)

        #places
        self.list_places = QTreeWidget(self)
        self.list_places.setRootIsDecorated(False)
        self.list_places.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.list_places.setHeaderLabel(QString.fromUtf8(_('Shortcuts')))
        self.second_splitter.addWidget(self.list_places)

        #files view stacked layout
        widget = QWidget(self)
        self.files_view_layout = QStackedLayout(widget)
        self.second_splitter.addWidget(widget)

        #folder don't exist label
        self.lbl_folder_dont_exists = QLabel(
            QString.fromUtf8(
                _('This directory don\'t exist\nin current snapshot !')), self)
        kde4tools.set_font_bold(self.lbl_folder_dont_exists)
        self.lbl_folder_dont_exists.setFrameShadow(QFrame.Sunken)
        self.lbl_folder_dont_exists.setFrameShape(QFrame.Panel)
        self.lbl_folder_dont_exists.setAlignment(Qt.AlignHCenter
                                                 | Qt.AlignVCenter)
        self.files_view_layout.addWidget(self.lbl_folder_dont_exists)

        #list files view
        self.list_files_view = QTreeView(self)
        self.files_view_layout.addWidget(self.list_files_view)
        self.list_files_view.setRootIsDecorated(False)
        self.list_files_view.setAlternatingRowColors(True)
        self.list_files_view.setAllColumnsShowFocus(True)
        self.list_files_view.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.list_files_view.setItemsExpandable(False)
        self.list_files_view.setDragEnabled(True)
        self.list_files_view.setDragDropMode(QAbstractItemView.DragOnly)

        self.list_files_view.header().setClickable(True)
        self.list_files_view.header().setMovable(False)
        self.list_files_view.header().setSortIndicatorShown(True)

        self.list_files_view_model = KDirModel(self)
        self.list_files_view_model.removeColumns(3, 2)
        self.list_files_view_model.dirLister().setAutoErrorHandlingEnabled(
            False, self)
        self.list_files_view_model.dirLister().setAutoUpdate(False)
        self.list_files_view_model.dirLister().setDelayedMimeTypes(False)
        self.list_files_view_model.dirLister().setMainWindow(self)

        self.list_files_view_sort_filter_proxy = KDirSortFilterProxyModel(self)
        self.list_files_view_sort_filter_proxy.setSourceModel(
            self.list_files_view_model)

        self.list_files_view.setModel(self.list_files_view_sort_filter_proxy)

        self.list_files_view_delegate = KFileItemDelegate(self)
        self.list_files_view.setItemDelegate(self.list_files_view_delegate)

        for column_index in xrange(3,
                                   self.list_files_view_model.columnCount()):
            self.list_files_view.hideColumn(column_index)

        sort_column = self.config.get_int_value(
            'kde4.main_window.files_view.sort.column', 0)
        sort_order = self.config.get_bool_value(
            'kde4.main_window.files_view.sort.ascending', True)
        if sort_order:
            sort_order = Qt.AscendingOrder
        else:
            sort_order = Qt.DescendingOrder

        self.list_files_view.header().setSortIndicator(sort_column, sort_order)
        self.list_files_view_sort_filter_proxy.sort(
            self.list_files_view.header().sortIndicatorSection(),
            self.list_files_view.header().sortIndicatorOrder())
        QObject.connect(self.list_files_view.header(),
                        SIGNAL('sortIndicatorChanged(int,Qt::SortOrder)'),
                        self.list_files_view_sort_filter_proxy.sort)

        self.files_view_layout.setCurrentWidget(self.list_files_view)

        #
        self.setCentralWidget(self.main_splitter)

        self.statusBar().showMessage(QString.fromUtf8(_('Done')))

        self.snapshots_list = []
        self.snapshot_id = '/'
        self.path = self.config.get_str_value('kde4.last_path', '/')
        self.edit_current_path.setText(self.path)

        #restore size and position
        x = self.config.get_int_value('kde4.main_window.x', -1)
        y = self.config.get_int_value('kde4.main_window.y', -1)
        if x >= 0 and y >= 0:
            self.move(x, y)

        w = self.config.get_int_value('kde4.main_window.width', 800)
        h = self.config.get_int_value('kde4.main_window.height', 500)
        self.resize(w, h)

        main_splitter_left_w = self.config.get_int_value(
            'kde4.main_window.main_splitter_left_w', 150)
        main_splitter_right_w = self.config.get_int_value(
            'kde4.main_window.main_splitter_right_w', 450)
        sizes = [main_splitter_left_w, main_splitter_right_w]
        self.main_splitter.setSizes(sizes)

        second_splitter_left_w = self.config.get_int_value(
            'kde4.main_window.second_splitter_left_w', 150)
        second_splitter_right_w = self.config.get_int_value(
            'kde4.main_window.second_splitter_right_w', 300)
        sizes = [second_splitter_left_w, second_splitter_right_w]
        self.second_splitter.setSizes(sizes)

        files_view_name_width = self.config.get_int_value(
            'kde4.main_window.files_view.name_width', -1)
        files_view_size_width = self.config.get_int_value(
            'kde4.main_window.files_view.size_width', -1)
        files_view_date_width = self.config.get_int_value(
            'kde4.main_window.files_view.date_width', -1)
        if files_view_name_width > 0 and files_view_size_width > 0 and files_view_date_width > 0:
            self.list_files_view.header().resizeSection(
                0, files_view_name_width)
            self.list_files_view.header().resizeSection(
                1, files_view_size_width)
            self.list_files_view.header().resizeSection(
                2, files_view_date_width)

        self.text_validator = QRegExpValidator(QRegExp('.*'), self)

        #
        kde4tools.set_font_bold(self.right_widget)

        #force settingdialog if it is not configured
        if not cfg.is_configured():
            kde4settingsdialog.SettingsDialog(self).exec_()

        if not cfg.is_configured():
            return

        if not cfg.can_backup():
            KMessageBox.error(
                self,
                QString.fromUtf8(
                    _('Can\'t find snapshots directory.\nIf it is on a removable drive please plug it and then press OK'
                      )))

        QObject.connect(self.list_files_view_model.dirLister(),
                        SIGNAL('completed()'), self.on_dir_lister_completed)
        QObject.connect(self.list_files_view_model.dirLister(),
                        SIGNAL('canceled()'), self.on_dir_lister_completed)

        #populate lists
        self.update_time_line()
        self.update_places()
        self.update_files_view(0)

        self.list_files_view.setFocus()

        self.update_snapshot_actions()

        QObject.connect(
            self.list_time_line,
            SIGNAL('currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)'),
            self.on_list_time_line_current_item_changed)
        QObject.connect(
            self.list_places,
            SIGNAL('currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)'),
            self.on_list_places_current_item_changed)
        QObject.connect(self.list_files_view,
                        SIGNAL('activated(const QModelIndex&)'),
                        self.on_list_files_view_item_activated)

        QObject.connect(self.btn_take_snapshot, SIGNAL('triggered()'),
                        self.on_btn_take_snapshot_clicked)
        QObject.connect(self.btn_update_snapshots, SIGNAL('triggered()'),
                        self.on_btn_update_snapshots_clicked)
        QObject.connect(self.btn_name_snapshot, SIGNAL('triggered()'),
                        self.on_btn_name_snapshot_clicked)
        QObject.connect(self.btn_remove_snapshot, SIGNAL('triggered()'),
                        self.on_btn_remove_snapshot_clicked)
        QObject.connect(self.btn_settings, SIGNAL('triggered()'),
                        self.on_btn_settings_clicked)
        QObject.connect(self.btn_about, SIGNAL('triggered()'),
                        self.on_btn_about_clicked)
        QObject.connect(self.btn_help, SIGNAL('triggered()'),
                        self.on_btn_help_clicked)
        QObject.connect(self.btn_quit, SIGNAL('triggered()'), self.close)
        QObject.connect(self.btn_folder_up, SIGNAL('triggered()'),
                        self.on_btn_folder_up_clicked)
        QObject.connect(self.btn_show_hidden_files, SIGNAL('toggled(bool)'),
                        self.on_btn_show_hidden_files_toggled)
        QObject.connect(self.btn_restore, SIGNAL('triggered()'),
                        self.on_btn_restore_clicked)
        QObject.connect(self.btn_copy, SIGNAL('triggered()'),
                        self.on_btn_copy_to_clipboard_clicked)
        QObject.connect(self.btn_snapshots, SIGNAL('triggered()'),
                        self.on_btn_snapshots_clicked)

        self.force_wait_lock_counter = 0

        self.timer_raise_application = QTimer(self)
        self.timer_raise_application.setInterval(1000)
        self.timer_raise_application.setSingleShot(False)
        QObject.connect(self.timer_raise_application, SIGNAL('timeout()'),
                        self.raise_application)
        self.timer_raise_application.start()

        self.timer_update_take_snapshot = QTimer(self)
        self.timer_update_take_snapshot.setInterval(1000)
        self.timer_update_take_snapshot.setSingleShot(False)
        QObject.connect(self.timer_update_take_snapshot, SIGNAL('timeout()'),
                        self.update_take_snapshot)
        self.timer_update_take_snapshot.start()
	def __init__( self, parent ):
		KDialog.__init__( self, parent )
		self.config = parent.config

		self.setWindowIcon( KIcon( 'configure' ) )
		self.setCaption( QString.fromUtf8( _( 'Settings' ) ) )

		self.main_widget = KTabWidget( self )
		self.setMainWidget( self.main_widget )

		#TAB: General
		tab_widget = QWidget( self )
		self.main_widget.addTab( tab_widget, QString.fromUtf8( _( 'General' ) ) )
		layout = QVBoxLayout( tab_widget )

		#Where to save snapshots
		group_box = QGroupBox( self )
		group_box.setTitle( QString.fromUtf8( _( 'Where to save snapshots' ) ) )
		layout.addWidget( group_box )

		hlayout = QHBoxLayout( group_box )

		self.edit_snapshots_path = KLineEdit( self.config.get_snapshots_path(), self )
		self.edit_snapshots_path.setReadOnly( True )
		hlayout.addWidget( self.edit_snapshots_path )

		self.btn_snapshots_path = KPushButton( KIcon( 'folder' ), '', self )
		hlayout.addWidget( self.btn_snapshots_path )
		QObject.connect( self.btn_snapshots_path, SIGNAL('clicked()'), self.on_btn_snapshots_path_clicked )

		#Schedule
		group_box = QGroupBox( self )
		self.global_schedule_group_box = group_box
		group_box.setTitle( QString.fromUtf8( _( 'Schedule' ) ) )
		layout.addWidget( group_box )

		hlayout = QHBoxLayout( group_box )

		self.combo_automatic_snapshots = KComboBox( self )
		hlayout.addWidget( self.combo_automatic_snapshots )
		self.fill_combo( self.combo_automatic_snapshots, self.config.AUTOMATIC_BACKUP_MODES, self.config.get_automatic_backup_mode() )

		#
		layout.addStretch()
		
		#TAB: Include
		tab_widget = QWidget( self )
		self.main_widget.addTab( tab_widget, QString.fromUtf8( _( 'Include' ) ) )
		layout = QVBoxLayout( tab_widget )

		self.list_include = QTreeWidget( self )
		self.list_include.setRootIsDecorated( False )
		#self.list_include.setEditTriggers( QAbstractItemView.NoEditTriggers )
		self.list_include.setHeaderLabels( [ QString.fromUtf8( _('Include folders') ), QString.fromUtf8( _('Automatic backup') ) ] )
		self.list_include.header().setResizeMode( 0, QHeaderView.Stretch )

		self.popup_automatic_backup = KMenu( self )
		keys = self.config.AUTOMATIC_BACKUP_MODES.keys()
		keys.sort()
		for key in keys:
			self.popup_automatic_backup.addAction( PopupAutomaticBackupAction( self.list_include, key, QString.fromUtf8( self.config.AUTOMATIC_BACKUP_MODES[ key ] ) ) )

		QObject.connect( self.list_include, SIGNAL('itemActivated(QTreeWidgetItem*,int)'), self.on_list_include_item_activated )
		layout.addWidget( self.list_include )

		for include in self.config.get_include_folders():
			self.add_include( include )
		
		buttons_layout = QHBoxLayout()
		layout.addLayout( buttons_layout )

		self.btn_include_add = KPushButton( KStandardGuiItem.add(), self )
		buttons_layout.addWidget( self.btn_include_add )
		QObject.connect( self.btn_include_add, SIGNAL('clicked()'), self.on_btn_include_add_clicked )
		
		self.btn_include_remove = KPushButton( KStandardGuiItem.remove(), self )
		buttons_layout.addWidget( self.btn_include_remove )
		QObject.connect( self.btn_include_remove, SIGNAL('clicked()'), self.on_btn_include_remove_clicked )

		#TAB: exclude
		tab_widget = QWidget( self )
		self.main_widget.addTab( tab_widget, QString.fromUtf8( _( 'Exclude' ) ) )
		layout = QVBoxLayout( tab_widget )

		self.list_exclude = KListWidget( self )
		layout.addWidget( self.list_exclude )
		
		for exclude in self.config.get_exclude_patterns():
			self.add_exclude( exclude )

		buttons_layout = QHBoxLayout()
		layout.addLayout( buttons_layout )

		self.btn_exclude_add = KPushButton( KStandardGuiItem.add(), self )
		buttons_layout.addWidget( self.btn_exclude_add )
		QObject.connect( self.btn_exclude_add, SIGNAL('clicked()'), self.on_btn_exclude_add_clicked )
		
		self.btn_exclude_file = KPushButton( KStandardGuiItem.add(), self )
		self.btn_exclude_file.setText( QString.fromUtf8( _( 'Add file' ) ) )
		buttons_layout.addWidget( self.btn_exclude_file )
		QObject.connect( self.btn_exclude_file, SIGNAL('clicked()'), self.on_btn_exclude_file_clicked )
		
		self.btn_exclude_folder = KPushButton( KStandardGuiItem.add(), self )
		self.btn_exclude_folder.setText( QString.fromUtf8( _( 'Add folder' ) ) )
		buttons_layout.addWidget( self.btn_exclude_folder )
		QObject.connect( self.btn_exclude_folder, SIGNAL('clicked()'), self.on_btn_exclude_folder_clicked )
		
		self.btn_exclude_remove = KPushButton( KStandardGuiItem.remove(), self )
		buttons_layout.addWidget( self.btn_exclude_remove )
		QObject.connect( self.btn_exclude_remove, SIGNAL('clicked()'), self.on_btn_exclude_remove_clicked )

		#TAB: Auto-remove
		tab_widget = QWidget( self )
		self.main_widget.addTab( tab_widget, QString.fromUtf8( _( 'Auto-remove' ) ) )
		layout = QGridLayout( tab_widget )

		#remove old snapshots
		enabled, value, unit = self.config.get_remove_old_snapshots()

		self.cb_remove_older_then = QCheckBox( QString.fromUtf8( _( 'Older than:' ) ), self )
		layout.addWidget( self.cb_remove_older_then, 0, 0 )
		self.cb_remove_older_then.setChecked( enabled )
		QObject.connect( self.cb_remove_older_then, SIGNAL('stateChanged(int)'), self.update_remove_older_than )

		self.edit_remove_older_then = KIntSpinBox( 1, 1000, 1, value, self )
		layout.addWidget( self.edit_remove_older_then, 0, 1 )

		self.combo_remove_older_then = KComboBox( self )
		layout.addWidget( self.combo_remove_older_then, 0, 2 )
		self.fill_combo( self.combo_remove_older_then, self.config.REMOVE_OLD_BACKUP_UNITS, unit )

		#min free space
		enabled, value, unit = self.config.get_min_free_space()

		self.cb_min_free_space = QCheckBox( QString.fromUtf8( _( 'If free space is less than:' ) ), self )
		layout.addWidget( self.cb_min_free_space, 1, 0 )
		self.cb_min_free_space.setChecked( enabled )
		QObject.connect( self.cb_min_free_space, SIGNAL('stateChanged(int)'), self.update_min_free_space )

		self.edit_min_free_space = KIntSpinBox( 1, 1000, 1, value, self )
		layout.addWidget( self.edit_min_free_space, 1, 1 )

		self.combo_min_free_space = KComboBox( self )
		layout.addWidget( self.combo_min_free_space, 1, 2 )
		self.fill_combo( self.combo_min_free_space, self.config.MIN_FREE_SPACE_UNITS, unit )

		#smart remove
		self.cb_smart_remove = QCheckBox( QString.fromUtf8( _( 'Smart remove' ) ), self )
		layout.addWidget( self.cb_smart_remove, 2, 0 )
		self.cb_smart_remove.setChecked( self.config.get_smart_remove() )

		label = QLabel( QString.fromUtf8( _( '- keep all snapshots from today and yesterday\n- keep one snapshot for the last week and one for two weeks ago\n- keep one snapshot per month for all previous months of this year\n- keep one snapshot per year for all previous years' ) ),self )
		label.setContentsMargins( 25, 0, 0, 0 )
		layout.addWidget( label, 3, 0 )

		#don't remove named snapshots
		self.cb_dont_remove_named_snapshots = QCheckBox( QString.fromUtf8( _( 'Don\'t remove named snapshots' ) ), self )
		layout.addWidget( self.cb_dont_remove_named_snapshots, 4, 0 )
		self.cb_dont_remove_named_snapshots.setChecked( self.config.get_dont_remove_named_snapshots() )

		#
		layout.addWidget( QWidget(), 5, 0 )
		layout.setRowStretch( 5, 2 )
		
		#TAB: Options
		tab_widget = QWidget( self )
		self.main_widget.addTab( tab_widget, QString.fromUtf8( _( 'Options' ) ) )
		layout = QVBoxLayout( tab_widget )

		self.cb_notify_enabled = QCheckBox( QString.fromUtf8( _( 'Enable notifications' ) ), self )
		layout.addWidget( self.cb_notify_enabled )
		self.cb_notify_enabled.setChecked( self.config.is_notify_enabled() )

		#
		layout.addStretch()

		#TAB: Expert Options
		tab_widget = QWidget( self )
		self.main_widget.addTab( tab_widget, QString.fromUtf8( _( 'Expert Options' ) ) )
		layout = QVBoxLayout( tab_widget )

		label = QLabel( QString.fromUtf8( _('Change this options only if you really know what you are doing !') ), self )
		kde4tools.set_font_bold( label )
		layout.addWidget( label )

		self.cb_per_diretory_schedule = QCheckBox( QString.fromUtf8( _( 'Enable schedule per included directory (see Include tab; default: disabled)' ) ), self )
		layout.addWidget( self.cb_per_diretory_schedule )
		self.cb_per_diretory_schedule.setChecked( self.config.get_per_directory_schedule() )
		QObject.connect( self.cb_per_diretory_schedule, SIGNAL('clicked()'), self.update_include_columns )

		#
		layout.addStretch()

		self.update_include_columns()

		self.update_remove_older_than()
		self.update_min_free_space()