コード例 #1
0
ファイル: management.py プロジェクト: guofengstc/everpad
 def __init__(self, app, *args, **kwargs):
     QDialog.__init__(self, *args, **kwargs)
     self.app = app
     self.closed = False
     self.startup_path = os.path.expanduser('~/.config/autostart/')
     self.startup_file = os.path.join(self.startup_path, 'everpad.desktop')
     self.ui = Ui_Dialog()
     self.ui.setupUi(self)
     self.ui.webView.hide()
     self.setWindowIcon(get_icon())
     for delay in (5, 10, 15, 30):
         self.ui.syncDelayBox.addItem(self.tr('%d minutes') % delay,
             userData=str(delay * 60 * 1000),
         )
     self.ui.syncDelayBox.addItem(self.tr('One hour'), userData='3600000')
     self.ui.syncDelayBox.addItem(self.tr('Manual'), userData='-1')
     active_index = self.ui.syncDelayBox.findData(str(
         self.app.provider.get_sync_delay(),
     ))
     self.ui.syncDelayBox.setCurrentIndex(active_index)
     self.ui.syncDelayBox.currentIndexChanged.connect(self.delay_changed)
     self.ui.tabWidget.currentChanged.connect(self.update_tabs)
     self.ui.authBtn.clicked.connect(self.change_auth)
     self.ui.autoStart.stateChanged.connect(self.auto_start_state)
     self.ui.noteFont.currentFontChanged.connect(self.font_changed)
     self.ui.noteSize.valueChanged.connect(self.font_size_changed)
     self.ui.blackTray.stateChanged.connect(self.tray_changed)
     self.update_tabs()
コード例 #2
0
 def __init__(self, *args, **kwargs):
     QDialog.__init__(self, *args, **kwargs)
     self.app = QApplication.instance()
     self.closed = False
     self.startup_path = os.path.expanduser('~/.config/autostart/')
     if not os.path.exists(self.startup_path):
         os.makedirs(self.startup_path)
     self.startup_file = os.path.join(self.startup_path, 'everpad.desktop')
     self.ui = Ui_Dialog()
     self.ui.setupUi(self)
     self.ui.webView.hide()
     self.setWindowIcon(get_icon())
     for delay in (5, 10, 15, 30):
         self.ui.syncDelayBox.addItem(
             self.tr('%d minutes') % delay,
             userData=str(delay * 60 * 1000),
         )
     self.ui.syncDelayBox.addItem(self.tr('One hour'), userData='3600000')
     self.ui.syncDelayBox.addItem(self.tr('Manual'), userData='-1')
     active_index = self.ui.syncDelayBox.findData(
         str(self.app.provider.get_sync_delay(), ))
     self.ui.syncDelayBox.setCurrentIndex(active_index)
     self.ui.syncDelayBox.currentIndexChanged.connect(self.delay_changed)
     self.ui.tabWidget.currentChanged.connect(self.update_tabs)
     self.ui.authBtn.clicked.connect(self.change_auth)
     self.ui.autoStart.stateChanged.connect(self.auto_start_state)
     self.ui.noteFont.currentFontChanged.connect(self.font_changed)
     self.ui.noteSize.valueChanged.connect(self.font_size_changed)
     self.ui.blackTray.stateChanged.connect(self.tray_changed)
     self.ui.progressCheckBox.stateChanged.connect(self.progress_changed)
     self.layout_list = self.ui.listWidget_indLayout
     self.layout_list.setContextMenuPolicy(Qt.CustomContextMenu)
     self.layout_list.customContextMenuRequested.connect(
         self.layout_list_contextMenu)
     layout_list_model = self.layout_list.model()
     layout_list_model.layoutChanged.connect(self.save_layout_list)
     self.layout_labels = {
         'create_note': self.tr('Create Note'),
         'pin_notes': self.tr('Pinned Notes'),
         'all_notes': self.tr('All Notes'),
         'notes': self.tr('Notes'),
         'sync': self.tr('Last Sync'),
     }
     self.load_layout_list(
         self.app.settings.value('menu-order', DEFAULT_INDICATOR_LAYOUT))
     self.ui.searchOnHome.stateChanged.connect(self.search_on_home_changed)
     self.ui.sortByNotebook.stateChanged.connect(
         self.sort_by_notebook_changed)
     self.ui.buttonBox.clicked.connect(self.close_clicked)
     self.update_tabs()
コード例 #3
0
ファイル: management.py プロジェクト: MikeyG/gevernote
 def __init__(self, *args, **kwargs):
     QDialog.__init__(self, *args, **kwargs)
     self.app = QApplication.instance()
     self.closed = False
     self.startup_path = os.path.expanduser('~/.config/autostart/')
     if not os.path.exists(self.startup_path):
         os.makedirs(self.startup_path)
     self.startup_file = os.path.join(self.startup_path, 'everpad.desktop')
     self.ui = Ui_Dialog()
     self.ui.setupUi(self)
     self.ui.webView.hide()
     self.setWindowIcon(get_icon())
     for delay in (5, 10, 15, 30):
         self.ui.syncDelayBox.addItem(self.tr('%d minutes') % delay,
             userData=str(delay * 60 * 1000),
         )
     self.ui.syncDelayBox.addItem(self.tr('One hour'), userData='3600000')
     self.ui.syncDelayBox.addItem(self.tr('Manual'), userData='-1')
     active_index = self.ui.syncDelayBox.findData(str(
         self.app.provider.get_sync_delay(),
     ))
     self.ui.syncDelayBox.setCurrentIndex(active_index)
     self.ui.syncDelayBox.currentIndexChanged.connect(self.delay_changed)
     self.ui.tabWidget.currentChanged.connect(self.update_tabs)
     self.ui.authBtn.clicked.connect(self.change_auth)
     self.ui.autoStart.stateChanged.connect(self.auto_start_state)
     self.ui.noteFont.currentFontChanged.connect(self.font_changed)
     self.ui.noteSize.valueChanged.connect(self.font_size_changed)
     self.ui.blackTray.stateChanged.connect(self.tray_changed)
     self.ui.progressCheckBox.stateChanged.connect(self.progress_changed)
     self.layout_list = self.ui.listWidget_indLayout
     self.layout_list.setContextMenuPolicy(Qt.CustomContextMenu)
     self.layout_list.customContextMenuRequested.connect(self.layout_list_contextMenu)
     layout_list_model = self.layout_list.model()
     layout_list_model.layoutChanged.connect(self.save_layout_list)
     self.layout_labels = {
         'create_note': self.tr('Create Note'),
         'pin_notes' : self.tr('Pinned Notes'),
         'all_notes' : self.tr('All Notes'),
         'notes'     : self.tr('Notes'),
         'sync'      : self.tr('Last Sync'),
         }
     self.load_layout_list(self.app.settings.value('menu-order', DEFAULT_INDICATOR_LAYOUT))
     self.ui.searchOnHome.stateChanged.connect(self.search_on_home_changed)
     self.ui.sortByNotebook.stateChanged.connect(self.sort_by_notebook_changed)
     self.ui.buttonBox.clicked.connect(self.close_clicked)
     self.update_tabs()
コード例 #4
0
ファイル: management.py プロジェクト: MikeyG/gevernote
class Management(QDialog):
    """Management dialog"""

    def __init__(self, *args, **kwargs):
        QDialog.__init__(self, *args, **kwargs)
        self.app = QApplication.instance()
        self.closed = False
        self.startup_path = os.path.expanduser('~/.config/autostart/')
        if not os.path.exists(self.startup_path):
            os.makedirs(self.startup_path)
        self.startup_file = os.path.join(self.startup_path, 'everpad.desktop')
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.ui.webView.hide()
        self.setWindowIcon(get_icon())
        for delay in (5, 10, 15, 30):
            self.ui.syncDelayBox.addItem(self.tr('%d minutes') % delay,
                userData=str(delay * 60 * 1000),
            )
        self.ui.syncDelayBox.addItem(self.tr('One hour'), userData='3600000')
        self.ui.syncDelayBox.addItem(self.tr('Manual'), userData='-1')
        active_index = self.ui.syncDelayBox.findData(str(
            self.app.provider.get_sync_delay(),
        ))
        self.ui.syncDelayBox.setCurrentIndex(active_index)
        self.ui.syncDelayBox.currentIndexChanged.connect(self.delay_changed)
        self.ui.tabWidget.currentChanged.connect(self.update_tabs)
        self.ui.authBtn.clicked.connect(self.change_auth)
        self.ui.autoStart.stateChanged.connect(self.auto_start_state)
        self.ui.noteFont.currentFontChanged.connect(self.font_changed)
        self.ui.noteSize.valueChanged.connect(self.font_size_changed)
        self.ui.blackTray.stateChanged.connect(self.tray_changed)
        self.ui.progressCheckBox.stateChanged.connect(self.progress_changed)
        self.layout_list = self.ui.listWidget_indLayout
        self.layout_list.setContextMenuPolicy(Qt.CustomContextMenu)
        self.layout_list.customContextMenuRequested.connect(self.layout_list_contextMenu)
        layout_list_model = self.layout_list.model()
        layout_list_model.layoutChanged.connect(self.save_layout_list)
        self.layout_labels = {
            'create_note': self.tr('Create Note'),
            'pin_notes' : self.tr('Pinned Notes'),
            'all_notes' : self.tr('All Notes'),
            'notes'     : self.tr('Notes'),
            'sync'      : self.tr('Last Sync'),
            }
        self.load_layout_list(self.app.settings.value('menu-order', DEFAULT_INDICATOR_LAYOUT))
        self.ui.searchOnHome.stateChanged.connect(self.search_on_home_changed)
        self.ui.sortByNotebook.stateChanged.connect(self.sort_by_notebook_changed)
        self.ui.buttonBox.clicked.connect(self.close_clicked)
        self.update_tabs()

    def on_default_layout(self):
        self.load_layout_list(DEFAULT_INDICATOR_LAYOUT)
        self.save_layout_list()

    def load_layout_list(self, settings):
        self.layout_list.clear()
        for menu_item in settings:
            font = QFont()
            if menu_item == 'pin_notes' or menu_item == 'notes':
                font.setStyle(QFont.StyleItalic)
            else:
                font.setWeight(QFont.DemiBold)
            item = QListWidgetItem(self.layout_labels[menu_item])
            item.setData(Qt.UserRole, menu_item)
            item.setTextAlignment(Qt.AlignCenter)
            item.setFont(font)
            self.layout_list.addItem(item)

    def layout_list_contextMenu(self, pos):
        menu = QMenu()
        default_action = menu.addAction(self.tr("Reset Layout"))
        default_action.triggered.connect(self.on_default_layout)
        menu.exec_(QCursor.pos())

    def save_layout_list(self):
        all_items = self.layout_list.findItems('*', Qt.MatchWildcard)
        user_settings = []
        for item in all_items:
            user_settings.append(item.data(Qt.UserRole))
        self.app.settings.setValue('menu-order', user_settings)

    @Slot(str)
    def font_size_changed(self, size):
        self.app.settings.setValue('note-font-size', size)

    @Slot(QFont)
    def font_changed(self, font):
        self.app.settings.setValue('note-font-family', font.family())

    @Slot()
    def tray_changed(self):
        if self.ui.blackTray.checkState() == Qt.Unchecked:
            self.app.settings.setValue('black-icon', 0)
        else:
            self.app.settings.setValue('black-icon', 1)
        self.app.update_icon()

    @Slot()
    def progress_changed(self):
        if self.ui.progressCheckBox.checkState() == Qt.Unchecked:
            self.app.settings.setValue('launcher-progress', 0)
        else:
            self.app.settings.setValue('launcher-progress', 1)

    @Slot()
    def search_on_home_changed(self):
        if self.ui.searchOnHome.checkState() == Qt.Unchecked:
            value = '0'
        else:
            value = '1'
        self.app.provider.set_settings_value('search-on-home', value)

    @Slot()
    def sort_by_notebook_changed(self):
        value = ('0' if self.ui.sortByNotebook.checkState() == Qt.Unchecked 
                     else '1')
        self.app.provider.set_settings_value('sort-by-notebook', value)

    @Slot()
    def update_tabs(self):
        if self.app.provider.is_authenticated():
            self.ui.authBtn.setText(self.tr('Remove Authorisation'))
        else:
            self.ui.authBtn.setText(self.tr('Authorize'))
        self.ui.autoStart.setCheckState(Qt.Checked
            if os.path.isfile(self.startup_file)
        else Qt.Unchecked)
        self.ui.noteFont.setCurrentFont(QFont(self.app.settings.value(
            'note-font-family', DEFAULT_FONT,
        )))
        self.ui.noteSize.setValue(int(self.app.settings.value(
            'note-font-size', DEFAULT_FONT_SIZE,
        )))
        self.ui.blackTray.setCheckState(Qt.Checked
            if int(self.app.settings.value('black-icon', 0))
        else Qt.Unchecked)
        self.ui.progressCheckBox.setCheckState(Qt.Checked
            if int(self.app.settings.value('launcher-progress', 1))
        else Qt.Unchecked)
        self.ui.searchOnHome.setCheckState(Qt.Checked
            if int(self.app.provider.get_settings_value('search-on-home') or 1)
        else Qt.Unchecked)
        self.ui.sortByNotebook.setCheckState(Qt.Checked
            if int(self.app.provider.get_settings_value('sort-by-notebook') or 0)
        else Qt.Unchecked)

    @Slot()
    def auto_start_state(self):
        if self.ui.autoStart.checkState() == Qt.Unchecked:
            try:
                os.unlink(self.startup_file)
            except OSError:
                pass
        else:
            shutil.copyfile(
                resource_filename('share/applications/everpad.desktop'),
                self.startup_file,
            )

    @Slot(int)
    def delay_changed(self, index):
        self.app.provider.set_sync_delay(
            int(self.ui.syncDelayBox.itemData(index)),
        )

    
    # change evernote account authorization 
    # 050214: Tried to install on my laptop and everything falls apart 
    # trying to authenticate WTH
    @Slot()
    def change_auth(self):
        # If we already are authenticated, this click sets up to
        # remove authentication ---
        if self.app.provider.is_authenticated( ):
            print "everpad remove"
            
            
            # You really want to do this???? LOL
            # MKG - want to move to provider
            msgBox = QMessageBox(
                QMessageBox.Critical,
                self.tr("You are trying to remove authorisation"),
                self.tr("""
                Are you sure want to remove authoristion?
                It remove all not synced changes!
                """.strip()),
                QMessageBox.Yes | QMessageBox.No
            )
            ret = msgBox.exec_()
            
            # 
            if ret == QMessageBox.Yes:
                # daemon.py
                self.app.provider.remove_authentication( )
                self.update_tabs()
        
        # If not athenticated then authenticate --- 
        else:
            #self.ui.tabWidget.hide()
            #self.ui.webView.show()
            self.app.provider.authenticate( )
            

        #self.ui.webView.hide()
        self.ui.tabWidget.show()
        self.update_tabs()
 
    @Slot()
    def close_clicked(self):
        self.close()
コード例 #5
0
ファイル: management.py プロジェクト: guofengstc/everpad
class Management(QDialog):
    """Management dialog"""

    def __init__(self, app, *args, **kwargs):
        QDialog.__init__(self, *args, **kwargs)
        self.app = app
        self.closed = False
        self.startup_path = os.path.expanduser('~/.config/autostart/')
        self.startup_file = os.path.join(self.startup_path, 'everpad.desktop')
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.ui.webView.hide()
        self.setWindowIcon(get_icon())
        for delay in (5, 10, 15, 30):
            self.ui.syncDelayBox.addItem(self.tr('%d minutes') % delay,
                userData=str(delay * 60 * 1000),
            )
        self.ui.syncDelayBox.addItem(self.tr('One hour'), userData='3600000')
        self.ui.syncDelayBox.addItem(self.tr('Manual'), userData='-1')
        active_index = self.ui.syncDelayBox.findData(str(
            self.app.provider.get_sync_delay(),
        ))
        self.ui.syncDelayBox.setCurrentIndex(active_index)
        self.ui.syncDelayBox.currentIndexChanged.connect(self.delay_changed)
        self.ui.tabWidget.currentChanged.connect(self.update_tabs)
        self.ui.authBtn.clicked.connect(self.change_auth)
        self.ui.autoStart.stateChanged.connect(self.auto_start_state)
        self.ui.noteFont.currentFontChanged.connect(self.font_changed)
        self.ui.noteSize.valueChanged.connect(self.font_size_changed)
        self.ui.blackTray.stateChanged.connect(self.tray_changed)
        self.update_tabs()

    @Slot(str)
    def font_size_changed(self, size):
        self.app.settings.setValue('note-font-size', size)

    @Slot(QFont)
    def font_changed(self, font):
        self.app.settings.setValue('note-font-family', font.family())

    @Slot()
    def tray_changed(self):
        if self.ui.blackTray.checkState() == Qt.Unchecked:
            self.app.settings.setValue('black-icon', 0)
        else:
            self.app.settings.setValue('black-icon', 1)
        self.app.update_icon()

    @Slot()
    def update_tabs(self):
        if get_auth_token():
            self.ui.authBtn.setText(self.tr('Remove Authorisation'))
        else:
            self.ui.authBtn.setText(self.tr('Authorise'))
        self.ui.autoStart.setCheckState(Qt.Checked
            if os.path.isfile(self.startup_file)
        else Qt.Unchecked)
        self.ui.noteFont.setCurrentFont(QFont(self.app.settings.value(
            'note-font-family', DEFAULT_FONT,
        )))
        self.ui.noteSize.setValue(int(self.app.settings.value(
            'note-font-size', DEFAULT_FONT_SIZE,
        )))
        self.ui.blackTray.setCheckState(Qt.Checked
            if int(self.app.settings.value('black-icon', 0))
        else Qt.Unchecked)

    @Slot()
    def auto_start_state(self):
        if self.ui.autoStart.checkState() == Qt.Unchecked:
            try:
                os.unlink(self.startup_file)
            except OSError:
                pass
        else:
            shutil.copyfile(
                '/usr/share/applications/everpad.desktop',
                self.startup_file,
            )

    @Slot(int)
    def delay_changed(self, index):
        self.app.provider.set_sync_delay(
            int(self.ui.syncDelayBox.itemData(index)),
        )

    @Slot()
    def change_auth(self):
        if get_auth_token():
            self.app.provider.remove_authentication()
            self.update_tabs()
        else:
            self.ui.tabWidget.hide()
            self.ui.webView.show()
            consumer = oauth.Consumer(CONSUMER_KEY, CONSUMER_SECRET)
            client = oauth.Client(consumer)
            resp, content = client.request(
                'https://%s/oauth?oauth_callback=' % HOST + urllib.quote('http://everpad/'), 
            'GET')
            data = dict(urlparse.parse_qsl(content))
            url = 'http://%s/OAuth.action?oauth_token=' % HOST + urllib.quote(data['oauth_token'])
            page = AuthPage(
                data['oauth_token'], data['oauth_token_secret'], self,
            )
            self.ui.webView.setPage(page)
            page.mainFrame().load(url)

    def auth_finished(self, token):
        self.app.provider.authenticate(token)
        self.ui.webView.hide()
        self.ui.tabWidget.show()
        self.update_tabs()

    def closeEvent(self, event):
        event.ignore()
        self.closed = True
        self.hide()
コード例 #6
0
class Management(QDialog):
    """Management dialog"""
    def __init__(self, *args, **kwargs):
        QDialog.__init__(self, *args, **kwargs)
        self.app = QApplication.instance()
        self.closed = False
        self.startup_path = os.path.expanduser('~/.config/autostart/')
        if not os.path.exists(self.startup_path):
            os.makedirs(self.startup_path)
        self.startup_file = os.path.join(self.startup_path, 'everpad.desktop')
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.ui.webView.hide()
        self.setWindowIcon(get_icon())
        for delay in (5, 10, 15, 30):
            self.ui.syncDelayBox.addItem(
                self.tr('%d minutes') % delay,
                userData=str(delay * 60 * 1000),
            )
        self.ui.syncDelayBox.addItem(self.tr('One hour'), userData='3600000')
        self.ui.syncDelayBox.addItem(self.tr('Manual'), userData='-1')
        active_index = self.ui.syncDelayBox.findData(
            str(self.app.provider.get_sync_delay(), ))
        self.ui.syncDelayBox.setCurrentIndex(active_index)
        self.ui.syncDelayBox.currentIndexChanged.connect(self.delay_changed)
        self.ui.tabWidget.currentChanged.connect(self.update_tabs)
        self.ui.authBtn.clicked.connect(self.change_auth)
        self.ui.autoStart.stateChanged.connect(self.auto_start_state)
        self.ui.noteFont.currentFontChanged.connect(self.font_changed)
        self.ui.noteSize.valueChanged.connect(self.font_size_changed)
        self.ui.blackTray.stateChanged.connect(self.tray_changed)
        self.ui.progressCheckBox.stateChanged.connect(self.progress_changed)
        self.layout_list = self.ui.listWidget_indLayout
        self.layout_list.setContextMenuPolicy(Qt.CustomContextMenu)
        self.layout_list.customContextMenuRequested.connect(
            self.layout_list_contextMenu)
        layout_list_model = self.layout_list.model()
        layout_list_model.layoutChanged.connect(self.save_layout_list)
        self.layout_labels = {
            'create_note': self.tr('Create Note'),
            'pin_notes': self.tr('Pinned Notes'),
            'all_notes': self.tr('All Notes'),
            'notes': self.tr('Notes'),
            'sync': self.tr('Last Sync'),
        }
        self.load_layout_list(
            self.app.settings.value('menu-order', DEFAULT_INDICATOR_LAYOUT))
        self.ui.searchOnHome.stateChanged.connect(self.search_on_home_changed)
        self.ui.sortByNotebook.stateChanged.connect(
            self.sort_by_notebook_changed)
        self.ui.buttonBox.clicked.connect(self.close_clicked)
        self.update_tabs()

    def on_default_layout(self):
        self.load_layout_list(DEFAULT_INDICATOR_LAYOUT)
        self.save_layout_list()

    def load_layout_list(self, settings):
        self.layout_list.clear()
        for menu_item in settings:
            font = QFont()
            if menu_item == 'pin_notes' or menu_item == 'notes':
                font.setStyle(QFont.StyleItalic)
            else:
                font.setWeight(QFont.DemiBold)
            item = QListWidgetItem(self.layout_labels[menu_item])
            item.setData(Qt.UserRole, menu_item)
            item.setTextAlignment(Qt.AlignCenter)
            item.setFont(font)
            self.layout_list.addItem(item)

    def layout_list_contextMenu(self, pos):
        menu = QMenu()
        default_action = menu.addAction(self.tr("Reset Layout"))
        default_action.triggered.connect(self.on_default_layout)
        menu.exec_(QCursor.pos())

    def save_layout_list(self):
        all_items = self.layout_list.findItems('*', Qt.MatchWildcard)
        user_settings = []
        for item in all_items:
            user_settings.append(item.data(Qt.UserRole))
        self.app.settings.setValue('menu-order', user_settings)

    @Slot(str)
    def font_size_changed(self, size):
        self.app.settings.setValue('note-font-size', size)

    @Slot(QFont)
    def font_changed(self, font):
        self.app.settings.setValue('note-font-family', font.family())

    @Slot()
    def tray_changed(self):
        if self.ui.blackTray.checkState() == Qt.Unchecked:
            self.app.settings.setValue('black-icon', 0)
        else:
            self.app.settings.setValue('black-icon', 1)
        self.app.update_icon()

    @Slot()
    def progress_changed(self):
        if self.ui.progressCheckBox.checkState() == Qt.Unchecked:
            self.app.settings.setValue('launcher-progress', 0)
        else:
            self.app.settings.setValue('launcher-progress', 1)

    @Slot()
    def search_on_home_changed(self):
        if self.ui.searchOnHome.checkState() == Qt.Unchecked:
            value = '0'
        else:
            value = '1'
        self.app.provider.set_settings_value('search-on-home', value)

    @Slot()
    def sort_by_notebook_changed(self):
        value = ('0' if self.ui.sortByNotebook.checkState() == Qt.Unchecked
                 else '1')
        self.app.provider.set_settings_value('sort-by-notebook', value)

    @Slot()
    def update_tabs(self):
        if self.app.provider.is_authenticated():
            self.ui.authBtn.setText(self.tr('Remove Authorisation'))
        else:
            self.ui.authBtn.setText(self.tr('Authorize'))
        self.ui.autoStart.setCheckState(
            Qt.Checked if os.path.isfile(self.startup_file) else Qt.Unchecked)
        self.ui.noteFont.setCurrentFont(
            QFont(self.app.settings.value(
                'note-font-family',
                DEFAULT_FONT,
            )))
        self.ui.noteSize.setValue(
            int(self.app.settings.value(
                'note-font-size',
                DEFAULT_FONT_SIZE,
            )))
        self.ui.blackTray.setCheckState(Qt.Checked if int(
            self.app.settings.value('black-icon', 0)) else Qt.Unchecked)
        self.ui.progressCheckBox.setCheckState(Qt.Checked if int(
            self.app.settings.value('launcher-progress', 1)) else Qt.Unchecked)
        self.ui.searchOnHome.setCheckState(Qt.Checked if int(
            self.app.provider.get_settings_value('search-on-home') or 1
        ) else Qt.Unchecked)
        self.ui.sortByNotebook.setCheckState(Qt.Checked if int(
            self.app.provider.get_settings_value('sort-by-notebook') or 0
        ) else Qt.Unchecked)

    @Slot()
    def auto_start_state(self):
        if self.ui.autoStart.checkState() == Qt.Unchecked:
            try:
                os.unlink(self.startup_file)
            except OSError:
                pass
        else:
            shutil.copyfile(
                resource_filename('share/applications/everpad.desktop'),
                self.startup_file,
            )

    @Slot(int)
    def delay_changed(self, index):
        self.app.provider.set_sync_delay(
            int(self.ui.syncDelayBox.itemData(index)), )

    # change evernote account authorization
    # 050214: Tried to install on my laptop and everything falls apart
    # trying to authenticate WTH
    @Slot()
    def change_auth(self):
        # If we already are authenticated, this click sets up to
        # remove authentication ---
        if self.app.provider.is_authenticated():
            print "everpad remove"

            # You really want to do this???? LOL
            # MKG - want to move to provider
            msgBox = QMessageBox(
                QMessageBox.Critical,
                self.tr("You are trying to remove authorisation"),
                self.tr("""
                Are you sure want to remove authoristion?
                It remove all not synced changes!
                """.strip()), QMessageBox.Yes | QMessageBox.No)
            ret = msgBox.exec_()

            #
            if ret == QMessageBox.Yes:
                # daemon.py
                self.app.provider.remove_authentication()
                self.update_tabs()

        # If not athenticated then authenticate ---
        else:
            #self.ui.tabWidget.hide()
            #self.ui.webView.show()
            self.app.provider.authenticate()

        #self.ui.webView.hide()
        self.ui.tabWidget.show()
        self.update_tabs()

    @Slot()
    def close_clicked(self):
        self.close()
コード例 #7
0
ファイル: management.py プロジェクト: freexploit/everpad
class Management(QDialog):
    """Management dialog"""

    def __init__(self, *args, **kwargs):
        QDialog.__init__(self, *args, **kwargs)
        self.app = QApplication.instance()
        self.closed = False
        self.startup_path = os.path.expanduser('~/.config/autostart/')
        if not os.path.exists(self.startup_path):
            os.makedirs(self.startup_path)
        self.startup_file = os.path.join(self.startup_path, 'everpad.desktop')
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.ui.webView.hide()
        self.setWindowIcon(get_icon())
        for delay in (5, 10, 15, 30):
            self.ui.syncDelayBox.addItem(self.tr('%d minutes') % delay,
                userData=str(delay * 60 * 1000),
            )
        self.ui.syncDelayBox.addItem(self.tr('One hour'), userData='3600000')
        self.ui.syncDelayBox.addItem(self.tr('Manual'), userData='-1')
        active_index = self.ui.syncDelayBox.findData(str(
            self.app.provider.get_sync_delay(),
        ))
        self.ui.syncDelayBox.setCurrentIndex(active_index)
        self.ui.syncDelayBox.currentIndexChanged.connect(self.delay_changed)
        self.ui.tabWidget.currentChanged.connect(self.update_tabs)
        self.ui.authBtn.clicked.connect(self.change_auth)
        self.ui.autoStart.stateChanged.connect(self.auto_start_state)
        self.ui.noteFont.currentFontChanged.connect(self.font_changed)
        self.ui.noteSize.valueChanged.connect(self.font_size_changed)
        self.ui.blackTray.stateChanged.connect(self.tray_changed)
        self.ui.progressCheckBox.stateChanged.connect(self.progress_changed)
        self.layout_list = self.ui.listWidget_indLayout
        self.layout_list.setContextMenuPolicy(Qt.CustomContextMenu)
        self.layout_list.customContextMenuRequested.connect(self.layout_list_contextMenu)
        layout_list_model = self.layout_list.model()
        layout_list_model.layoutChanged.connect(self.save_layout_list)
        self.layout_labels = {
            'create_note': self.tr('Create Note'),
            'pin_notes' : self.tr('Pinned Notes'),
            'all_notes' : self.tr('All Notes'),
            'notes'     : self.tr('Notes'),
            'sync'      : self.tr('Last Sync'),
            }
        self.load_layout_list(self.app.settings.value('menu-order', DEFAULT_INDICATOR_LAYOUT))
        self.ui.searchOnHome.stateChanged.connect(self.search_on_home_changed)
        self.ui.sortByNotebook.stateChanged.connect(self.sort_by_notebook_changed)
        self.ui.buttonBox.clicked.connect(self.close_clicked)
        self.update_tabs()

    def on_default_layout(self):
        self.load_layout_list(DEFAULT_INDICATOR_LAYOUT)
        self.save_layout_list()

    def load_layout_list(self, settings):
        self.layout_list.clear()
        for menu_item in settings:
            font = QFont()
            if menu_item == 'pin_notes' or menu_item == 'notes':
                font.setStyle(QFont.StyleItalic)
            else:
                font.setWeight(QFont.DemiBold)
            item = QListWidgetItem(self.layout_labels[menu_item])
            item.setData(Qt.UserRole, menu_item)
            item.setTextAlignment(Qt.AlignCenter)
            item.setFont(font)
            self.layout_list.addItem(item)

    def layout_list_contextMenu(self, pos):
        menu = QMenu()
        default_action = menu.addAction(self.tr("Reset Layout"))
        default_action.triggered.connect(self.on_default_layout)
        menu.exec_(QCursor.pos())

    def save_layout_list(self):
        all_items = self.layout_list.findItems('*', Qt.MatchWildcard)
        user_settings = []
        for item in all_items:
            user_settings.append(item.data(Qt.UserRole))
        self.app.settings.setValue('menu-order', user_settings)

    @Slot(str)
    def font_size_changed(self, size):
        self.app.settings.setValue('note-font-size', size)

    @Slot(QFont)
    def font_changed(self, font):
        self.app.settings.setValue('note-font-family', font.family())

    @Slot()
    def tray_changed(self):
        if self.ui.blackTray.checkState() == Qt.Unchecked:
            self.app.settings.setValue('black-icon', 0)
        else:
            self.app.settings.setValue('black-icon', 1)
        self.app.update_icon()

    @Slot()
    def progress_changed(self):
        if self.ui.progressCheckBox.checkState() == Qt.Unchecked:
            self.app.settings.setValue('launcher-progress', 0)
        else:
            self.app.settings.setValue('launcher-progress', 1)

    @Slot()
    def search_on_home_changed(self):
        if self.ui.searchOnHome.checkState() == Qt.Unchecked:
            value = '0'
        else:
            value = '1'
        self.app.provider.set_settings_value('search-on-home', value)

    @Slot()
    def sort_by_notebook_changed(self):
        value = ('0' if self.ui.sortByNotebook.checkState() == Qt.Unchecked 
                     else '1')
        self.app.provider.set_settings_value('sort-by-notebook', value)

    @Slot()
    def update_tabs(self):
        if self.app.provider.is_authenticated():
            self.ui.authBtn.setText(self.tr('Remove Authorisation'))
        else:
            self.ui.authBtn.setText(self.tr('Authorise'))
        self.ui.autoStart.setCheckState(Qt.Checked
            if os.path.isfile(self.startup_file)
        else Qt.Unchecked)
        self.ui.noteFont.setCurrentFont(QFont(self.app.settings.value(
            'note-font-family', DEFAULT_FONT,
        )))
        self.ui.noteSize.setValue(int(self.app.settings.value(
            'note-font-size', DEFAULT_FONT_SIZE,
        )))
        self.ui.blackTray.setCheckState(Qt.Checked
            if int(self.app.settings.value('black-icon', 0))
        else Qt.Unchecked)
        self.ui.progressCheckBox.setCheckState(Qt.Checked
            if int(self.app.settings.value('launcher-progress', 1))
        else Qt.Unchecked)
        self.ui.searchOnHome.setCheckState(Qt.Checked
            if int(self.app.provider.get_settings_value('search-on-home') or 1)
        else Qt.Unchecked)
        self.ui.sortByNotebook.setCheckState(Qt.Checked
            if int(self.app.provider.get_settings_value('sort-by-notebook') or 0)
        else Qt.Unchecked)

    @Slot()
    def auto_start_state(self):
        if self.ui.autoStart.checkState() == Qt.Unchecked:
            try:
                os.unlink(self.startup_file)
            except OSError:
                pass
        else:
            shutil.copyfile(
                resource_filename('share/applications/everpad.desktop'),
                self.startup_file,
            )

    @Slot(int)
    def delay_changed(self, index):
        self.app.provider.set_sync_delay(
            int(self.ui.syncDelayBox.itemData(index)),
        )

    @Slot()
    def change_auth(self):
        if self.app.provider.is_authenticated():
            msgBox = QMessageBox(
                QMessageBox.Critical,
                self.tr("You are trying to remove authorisation"),
                self.tr("""
                Are you sure want to remove authoristion?
                It remove all not synced changes!
                """.strip()),
                QMessageBox.Yes | QMessageBox.No
            )
            ret = msgBox.exec_()
            if ret == QMessageBox.Yes:
                self.app.provider.remove_authentication()
                self.update_tabs()
        else:
            self.ui.tabWidget.hide()
            self.ui.webView.show()
            consumer = oauth.Consumer(CONSUMER_KEY, CONSUMER_SECRET)
            client = oauth.Client(consumer, proxy_info=get_oauth_proxy('https'))
            resp, content = client.request(
                'https://%s/oauth?oauth_callback=' % HOST + urllib.quote('http://everpad/'),
            'GET')
            data = dict(urlparse.parse_qsl(content))
            url = 'http://%s/OAuth.action?oauth_token=' % HOST + urllib.quote(data['oauth_token'])
            page = AuthPage(
                data['oauth_token'], data['oauth_token_secret'], self,
            )
            self.ui.webView.setPage(page)
            page.mainFrame().load(url)

    @Slot()
    def close_clicked(self):
        self.close()

    def auth_finished(self, token):
        self.app.provider.authenticate(token)
        self.ui.webView.hide()
        self.ui.tabWidget.show()
        self.update_tabs()

    def closeEvent(self, event):
        event.ignore()
        self.closed = True
        self.hide()
コード例 #8
0
class Management(QDialog):
    """Management dialog"""

    def __init__(self, *args, **kwargs):
        QDialog.__init__(self, *args, **kwargs)
        self.app = QApplication.instance()
        self.closed = False
        self.startup_path = os.path.expanduser('~/.config/autostart/')
        if not os.path.exists(self.startup_path):
            os.makedirs(self.startup_path)
        self.startup_file = os.path.join(self.startup_path, 'everpad.desktop')
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.ui.webView.hide()
        self.setWindowIcon(get_icon())
        for delay in (5, 10, 15, 30):
            self.ui.syncDelayBox.addItem(self.tr('%d minutes') % delay,
                userData=str(delay * 60 * 1000),
            )
        self.ui.syncDelayBox.addItem(self.tr('One hour'), userData='3600000')
        self.ui.syncDelayBox.addItem(self.tr('Manual'), userData='-1')
        active_index = self.ui.syncDelayBox.findData(str(
            self.app.provider.get_sync_delay(),
        ))
        self.ui.syncDelayBox.setCurrentIndex(active_index)
        self.ui.syncDelayBox.currentIndexChanged.connect(self.delay_changed)
        self.ui.tabWidget.currentChanged.connect(self.update_tabs)
        self.ui.authBtn.clicked.connect(self.change_auth)
        self.ui.autoStart.stateChanged.connect(self.auto_start_state)
        self.ui.noteFont.currentFontChanged.connect(self.font_changed)
        self.ui.noteSize.valueChanged.connect(self.font_size_changed)
        self.ui.blackTray.stateChanged.connect(self.tray_changed)
        self.ui.progressCheckBox.stateChanged.connect(self.progress_changed)
        self.layout_list = self.ui.listWidget_indLayout
        self.layout_list.setContextMenuPolicy(Qt.CustomContextMenu)
        self.layout_list.customContextMenuRequested.connect(self.layout_list_contextMenu)
        layout_list_model = self.layout_list.model()
        layout_list_model.layoutChanged.connect(self.save_layout_list)
        self.layout_labels = {
            'create_note': self.tr('Create Note'),
            'pin_notes' : self.tr('Pinned Notes'),
            'all_notes' : self.tr('All Notes'),
            'notes'     : self.tr('Notes'),
            'sync'      : self.tr('Last Sync'),
            }
        self.load_layout_list(self.app.settings.value('menu-order', DEFAULT_INDICATOR_LAYOUT))
        self.ui.searchOnHome.stateChanged.connect(self.search_on_home_changed)
        self.ui.buttonBox.clicked.connect(self.close_clicked)
        self.update_tabs()

    def on_default_layout(self):
        self.load_layout_list(DEFAULT_INDICATOR_LAYOUT)
        self.save_layout_list()

    def load_layout_list(self, settings):
        self.layout_list.clear()
        for menu_item in settings:
            font = QFont()
            if menu_item == 'pin_notes' or menu_item == 'notes':
                font.setStyle(QFont.StyleItalic)
            else:
                font.setWeight(QFont.DemiBold)
            item = QListWidgetItem(self.layout_labels[menu_item])
            item.setData(Qt.UserRole, menu_item)
            item.setTextAlignment(Qt.AlignCenter)
            item.setFont(font)
            self.layout_list.addItem(item)

    def layout_list_contextMenu(self, pos):
        menu = QMenu()
        default_action = menu.addAction(self.tr("Reset Layout"))
        default_action.triggered.connect(self.on_default_layout)
        menu.exec_(QCursor.pos())

    def save_layout_list(self):
        all_items = self.layout_list.findItems('*', Qt.MatchWildcard)
        user_settings = []
        for item in all_items:
            user_settings.append(item.data(Qt.UserRole))
        self.app.settings.setValue('menu-order', user_settings)

    @Slot(str)
    def font_size_changed(self, size):
        self.app.settings.setValue('note-font-size', size)

    @Slot(QFont)
    def font_changed(self, font):
        self.app.settings.setValue('note-font-family', font.family())

    @Slot()
    def tray_changed(self):
        if self.ui.blackTray.checkState() == Qt.Unchecked:
            self.app.settings.setValue('black-icon', 0)
        else:
            self.app.settings.setValue('black-icon', 1)
        self.app.update_icon()

    @Slot()
    def progress_changed(self):
        if self.ui.progressCheckBox.checkState() == Qt.Unchecked:
            self.app.settings.setValue('launcher-progress', 0)
        else:
            self.app.settings.setValue('launcher-progress', 1)

    @Slot()
    def search_on_home_changed(self):
        if self.ui.searchOnHome.checkState() == Qt.Unchecked:
            value = '0'
        else:
            value = '1'
        self.app.provider.set_settings_value('search-on-home', value)

    @Slot()
    def update_tabs(self):
        if self.app.provider.is_authenticated():
            self.ui.authBtn.setText(self.tr('Remove Authorisation'))
        else:
            self.ui.authBtn.setText(self.tr('Authorise'))
        self.ui.autoStart.setCheckState(Qt.Checked
            if os.path.isfile(self.startup_file)
        else Qt.Unchecked)
        self.ui.noteFont.setCurrentFont(QFont(self.app.settings.value(
            'note-font-family', DEFAULT_FONT,
        )))
        self.ui.noteSize.setValue(int(self.app.settings.value(
            'note-font-size', DEFAULT_FONT_SIZE,
        )))
        self.ui.blackTray.setCheckState(Qt.Checked
            if int(self.app.settings.value('black-icon', 0))
        else Qt.Unchecked)
        self.ui.progressCheckBox.setCheckState(Qt.Checked
            if int(self.app.settings.value('launcher-progress', 1))
        else Qt.Unchecked)
        self.ui.searchOnHome.setCheckState(Qt.Checked
            if int(self.app.provider.get_settings_value('search-on-home') or 1)
        else Qt.Unchecked)

    @Slot()
    def auto_start_state(self):
        if self.ui.autoStart.checkState() == Qt.Unchecked:
            try:
                os.unlink(self.startup_file)
            except OSError:
                pass
        else:
            shutil.copyfile(
                resource_filename('share/applications/everpad.desktop'),
                self.startup_file,
            )

    @Slot(int)
    def delay_changed(self, index):
        self.app.provider.set_sync_delay(
            int(self.ui.syncDelayBox.itemData(index)),
        )

    @Slot()
    def change_auth(self):
        if self.app.provider.is_authenticated():
            msgBox = QMessageBox(
                QMessageBox.Critical,
                self.tr("You are trying to remove authorisation"),
                self.tr("""
                Are you sure want to remove authoristion?
                It remove all not synced changes!
                """.strip()),
                QMessageBox.Yes | QMessageBox.No
            )
            ret = msgBox.exec_()
            if ret == QMessageBox.Yes:
                self.app.provider.remove_authentication()
                self.update_tabs()
        else:
            self.ui.tabWidget.hide()
            self.ui.webView.show()
            consumer = oauth.Consumer(CONSUMER_KEY, CONSUMER_SECRET)
            client = oauth.Client(consumer, proxy_info=get_oauth_proxy('https'))
            resp, content = client.request(
                'https://%s/oauth?oauth_callback=' % HOST + urllib.quote('http://everpad/'),
            'GET')
            data = dict(urlparse.parse_qsl(content))
            url = 'http://%s/OAuth.action?oauth_token=' % HOST + urllib.quote(data['oauth_token'])
            page = AuthPage(
                data['oauth_token'], data['oauth_token_secret'], self,
            )
            self.ui.webView.setPage(page)
            page.mainFrame().load(url)

    @Slot()
    def close_clicked(self):
        self.close()

    def auth_finished(self, token):
        self.app.provider.authenticate(token)
        self.ui.webView.hide()
        self.ui.tabWidget.show()
        self.update_tabs()

    def closeEvent(self, event):
        event.ignore()
        self.closed = True
        self.hide()
コード例 #9
0
ファイル: management.py プロジェクト: cas--/everpad
class Management(QDialog):
    """Management dialog"""
    def __init__(self, *args, **kwargs):
        QDialog.__init__(self, *args, **kwargs)
        self.app = QApplication.instance()
        self.closed = False
        self.startup_path = os.path.expanduser('~/.config/autostart/')
        if not os.path.exists(self.startup_path):
            os.makedirs(self.startup_path)
        self.startup_file = os.path.join(self.startup_path, 'everpad.desktop')
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.ui.webView.hide()
        self.setWindowIcon(get_icon())
        for delay in (5, 10, 15, 30):
            self.ui.syncDelayBox.addItem(
                self.tr('%d minutes') % delay,
                userData=str(delay * 60 * 1000),
            )
        self.ui.syncDelayBox.addItem(self.tr('One hour'), userData='3600000')
        self.ui.syncDelayBox.addItem(self.tr('Manual'), userData='-1')
        active_index = self.ui.syncDelayBox.findData(
            str(self.app.provider.get_sync_delay(), ))
        self.ui.syncDelayBox.setCurrentIndex(active_index)
        self.ui.syncDelayBox.currentIndexChanged.connect(self.delay_changed)
        self.ui.tabWidget.currentChanged.connect(self.update_tabs)
        self.ui.authBtn.clicked.connect(self.change_auth)
        self.ui.autoStart.stateChanged.connect(self.auto_start_state)
        self.ui.noteFont.currentFontChanged.connect(self.font_changed)
        self.ui.noteSize.valueChanged.connect(self.font_size_changed)
        self.ui.blackTray.stateChanged.connect(self.tray_changed)
        self.ui.progressCheckBox.stateChanged.connect(self.progress_changed)
        self.ui.searchOnHome.stateChanged.connect(self.search_on_home_changed)
        self.ui.buttonBox.clicked.connect(self.close_clicked)
        self.update_tabs()

    @Slot(str)
    def font_size_changed(self, size):
        self.app.settings.setValue('note-font-size', size)

    @Slot(QFont)
    def font_changed(self, font):
        self.app.settings.setValue('note-font-family', font.family())

    @Slot()
    def tray_changed(self):
        if self.ui.blackTray.checkState() == Qt.Unchecked:
            self.app.settings.setValue('black-icon', 0)
        else:
            self.app.settings.setValue('black-icon', 1)
        self.app.update_icon()

    @Slot()
    def progress_changed(self):
        if self.ui.progressCheckBox.checkState() == Qt.Unchecked:
            self.app.settings.setValue('launcher-progress', 0)
        else:
            self.app.settings.setValue('launcher-progress', 1)

    @Slot()
    def search_on_home_changed(self):
        if self.ui.searchOnHome.checkState() == Qt.Unchecked:
            value = '0'
        else:
            value = '1'
        self.app.provider.set_settings_value('search-on-home', value)

    @Slot()
    def update_tabs(self):
        if self.app.provider.is_authenticated():
            self.ui.authBtn.setText(self.tr('Remove Authorisation'))
        else:
            self.ui.authBtn.setText(self.tr('Authorise'))
        self.ui.autoStart.setCheckState(
            Qt.Checked if os.path.isfile(self.startup_file) else Qt.Unchecked)
        self.ui.noteFont.setCurrentFont(
            QFont(self.app.settings.value(
                'note-font-family',
                DEFAULT_FONT,
            )))
        self.ui.noteSize.setValue(
            int(self.app.settings.value(
                'note-font-size',
                DEFAULT_FONT_SIZE,
            )))
        self.ui.blackTray.setCheckState(Qt.Checked if int(
            self.app.settings.value('black-icon', 0)) else Qt.Unchecked)
        self.ui.progressCheckBox.setCheckState(Qt.Checked if int(
            self.app.settings.value('launcher-progress', 1)) else Qt.Unchecked)
        self.ui.searchOnHome.setCheckState(Qt.Checked if int(
            self.app.provider.get_settings_value('search-on-home') or 1
        ) else Qt.Unchecked)

    @Slot()
    def auto_start_state(self):
        if self.ui.autoStart.checkState() == Qt.Unchecked:
            try:
                os.unlink(self.startup_file)
            except OSError:
                pass
        else:
            shutil.copyfile(
                resource_filename('share/applications/everpad.desktop'),
                self.startup_file,
            )

    @Slot(int)
    def delay_changed(self, index):
        self.app.provider.set_sync_delay(
            int(self.ui.syncDelayBox.itemData(index)), )

    @Slot()
    def change_auth(self):
        if self.app.provider.is_authenticated():
            msgBox = QMessageBox(
                QMessageBox.Critical,
                self.tr("You are trying to remove authorisation"),
                self.tr("""
                Are you sure want to remove authoristion?
                It remove all not synced changes!
                """.strip()), QMessageBox.Yes | QMessageBox.No)
            ret = msgBox.exec_()
            if ret == QMessageBox.Yes:
                self.app.provider.remove_authentication()
                self.update_tabs()
        else:
            self.ui.tabWidget.hide()
            self.ui.webView.show()
            consumer = oauth.Consumer(CONSUMER_KEY, CONSUMER_SECRET)
            client = oauth.Client(consumer,
                                  proxy_info=get_oauth_proxy('https'))
            resp, content = client.request(
                'https://%s/oauth?oauth_callback=' % HOST +
                urllib.quote('http://everpad/'), 'GET')
            data = dict(urlparse.parse_qsl(content))
            url = 'http://%s/OAuth.action?oauth_token=' % HOST + urllib.quote(
                data['oauth_token'])
            page = AuthPage(
                data['oauth_token'],
                data['oauth_token_secret'],
                self,
            )
            self.ui.webView.setPage(page)
            page.mainFrame().load(url)

    @Slot()
    def close_clicked(self):
        self.close()

    def auth_finished(self, token):
        self.app.provider.authenticate(token)
        self.ui.webView.hide()
        self.ui.tabWidget.show()
        self.update_tabs()

    def closeEvent(self, event):
        event.ignore()
        self.closed = True
        self.hide()
コード例 #10
0
ファイル: management.py プロジェクト: fabianofranz/everpad
class Management(QDialog):
    """Management dialog"""

    def __init__(self, app, *args, **kwargs):
        QDialog.__init__(self, *args, **kwargs)
        self.app = app
        self.closed = False
        self.startup_path = os.path.expanduser('~/.config/autostart/')
        self.startup_file = os.path.join(self.startup_path, 'everpad.desktop')
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.setWindowIcon(get_icon())
        for delay in (5, 10, 15, 30):
            self.ui.syncDelayBox.addItem(self.tr('%d minutes') % delay,
                userData=str(delay * 60 * 1000),
            )
        self.ui.syncDelayBox.addItem(self.tr('One hour'), userData='3600000')
        self.ui.syncDelayBox.addItem(self.tr('Manual'), userData='-1')
        active_index = self.ui.syncDelayBox.findData(str(
            self.app.provider.get_sync_delay(),
        ))
        self.ui.syncDelayBox.setCurrentIndex(active_index)
        self.ui.syncDelayBox.currentIndexChanged.connect(self.delay_changed)
        self.ui.tabWidget.currentChanged.connect(self.update_tabs)
        self.ui.createNotebook.clicked.connect(self.create_notebook)
        self.ui.authBtn.clicked.connect(self.change_auth)
        self.ui.autoStart.stateChanged.connect(self.auto_start_state)
        self.update_tabs()

    @Slot()
    def update_tabs(self):
        if get_auth_token():
            self.ui.authBtn.setText(self.tr('Remove Authorisation'))
            self.ui.notebookTab.setEnabled(True)
            self.init_notebooks()
        else:
            self.ui.authBtn.setText(self.tr('Authorise'))
            self.ui.notebookTab.setEnabled(False)
        self.ui.autoStart.setCheckState(Qt.Checked
            if os.path.isfile(self.startup_file)
        else Qt.Unchecked)

    @Slot()
    def auto_start_state(self):
        if self.ui.autoStart.checkState() == Qt.Unchecked:
            try:
                os.unlink(self.startup_file)
            except OSError:
                pass
        else:
            print self.startup_file
            shutil.copyfile(
                '/usr/share/applications/everpad.desktop',
                self.startup_file,
            )

    @Slot(int)
    def delay_changed(self, index):
        self.app.provider.set_sync_delay(
            int(self.ui.syncDelayBox.itemData(index)),
        )

    @Slot()
    def change_auth(self):
        if get_auth_token():
            self.app.provider.remove_authentication()
        else:
            consumer = oauth.Consumer(CONSUMER_KEY, CONSUMER_SECRET)
            client = oauth.Client(consumer)
            resp, content = client.request(
                'https://%s/oauth?oauth_callback=' % HOST + urllib.quote('http://localhost:15216/'), 
            'GET')
            data = dict(urlparse.parse_qsl(content))
            url = 'https://%s/OAuth.action?oauth_token=' % HOST + urllib.quote(data['oauth_token'])
            webbrowser.open(url)
            os.system('killall everpad-web-auth')
            try:
                subprocess.Popen([
                    'everpad-web-auth', '--token', data['oauth_token'],
                    '--secret', data['oauth_token_secret'],
                ])
            except OSError:
                subprocess.Popen([
                    'python', '../auth.py', '--token',
                    data['oauth_token'], '--secret',
                    data['oauth_token_secret'],
                ])
        self.update_tabs()

    def init_notebooks(self):
        frame = QFrame()
        layout = QVBoxLayout()
        frame.setLayout(layout)
        self.ui.scrollArea.setWidget(frame)
        for notebook_struct in self.app.provider.list_notebooks():
            notebook = Notebook.from_tuple(notebook_struct)
            count = self.app.provider.get_notebook_notes_count(notebook.id)
            widget = QWidget()
            menu = QMenu(self)
            menu.addAction(self.tr('Change Name'), Slot()(partial(
                self.change_notebook, notebook=notebook,
            )))
            action = menu.addAction(self.tr('Remove Notebook'), Slot()(partial(
                self.remove_notebook, notebook=notebook,
            )))
            action.setEnabled(False)
            widget.ui = Ui_Notebook()
            widget.ui.setupUi(widget)
            widget.ui.name.setText(notebook.name)
            widget.ui.content.setText(self.tr('Containts %d notes') % count)
            widget.ui.actionBtn.setIcon(QIcon.fromTheme('gtk-properties'))
            widget.setFixedHeight(50)
            layout.addWidget(widget)
            widget.ui.actionBtn.clicked.connect(Slot()(partial(
                self.show_notebook_menu,
                menu=menu, widget=widget,
            )))

    def show_notebook_menu(self, menu, widget):
        pos = widget.mapToGlobal(widget.ui.actionBtn.pos())
        pos.setY(pos.y() + widget.ui.actionBtn.geometry().height() / 2)
        pos.setX(pos.x() + widget.ui.actionBtn.geometry().width() / 2)
        menu.exec_(pos)

    def remove_notebook(self, notebook):
        msg = QMessageBox(
            QMessageBox.Critical,
            self.tr("You try to delete a notebook"),
            self.tr("Are you sure want to delete this notebook and notes in it?"),
            QMessageBox.Yes | QMessageBox.No
        )
        ret = msg.exec_()
        if ret == QMessageBox.Yes:
            self.app.provider.delete_notebook(notebook.id)
            self.app.send_notify(u'Notebook "%s" deleted!' % notebook.name)
            self.update_tabs()

    def change_notebook(self, notebook):
        name, status = self._notebook_new_name(
            self.tr('Change notebook name'), notebook.name,
        )
        if status:
            notebook.name = name
            self.app.provider.update_notebook(notebook.struct)
            self.app.send_notify(u'Notebook "%s" renamed!' % notebook.name)
            self.update_tabs()

    @Slot()
    def create_notebook(self):
        name, status = self._notebook_new_name(
            self.tr('Create new notebook'),
        )
        if status:
            self.app.provider.create_notebook(name)
            self.app.send_notify(u'Notebook "%s" created!' % name)
            self.update_tabs()

    def _notebook_new_name(self, title, exclude=''):
        names = map(lambda nb: Notebook.from_tuple(nb).name,
            self.app.provider.list_notebooks(),
        )
        try:
            names.remove(exclude)
        except ValueError:
            pass
        name, status = QInputDialog.getText(self, title,
            self.tr('Enter notebook name:'),
        )
        while name in names and status:
            name, status = QInputDialog.getText(self, title,
                self.tr('Notebook with this name already exist. Enter notebook name'),
            )
        return name, status

    def closeEvent(self, event):
        event.ignore()
        self.closed = True
        self.hide()