Permalink
Browse files

Add option to sort by notebook, fix sync bug

Adds an option to sort in the indicator by notebook,
and fixes a bug where sync would never run after
de-authorizing (unless the daemon was restarted)
  • Loading branch information...
dano committed Mar 10, 2013
1 parent 4cbe2b8 commit 0b7e4482a3046178d3baec44951c77a613253105
@@ -5,4 +5,4 @@ from everpad.pad import indicator
if __name__ == '__main__':
indicator.main()
indicator.main()
@@ -2,8 +2,8 @@
# Form implementation generated from reading ui file 'management.ui'
#
# Created: Sat Mar 2 22:53:08 2013
# by: pyside-uic 0.2.13 running on PySide 1.1.0
# Created: Sun Mar 10 14:15:51 2013
# by: pyside-uic 0.2.13 running on PySide 1.1.1
#
# WARNING! All changes made in this file will be lost!
@@ -79,16 +79,23 @@ def setupUi(self, Dialog):
self.searchOnHome.setText("")
self.searchOnHome.setObjectName("searchOnHome")
self.gridLayout_2.addWidget(self.searchOnHome, 4, 1, 1, 1)
self.label_8 = QtGui.QLabel(self.tab_2)
self.label_8.setObjectName("label_8")
self.gridLayout_2.addWidget(self.label_8, 5, 0, 1, 1)
self.sortByNotebook = QtGui.QCheckBox(self.tab_2)
self.sortByNotebook.setText("")
self.sortByNotebook.setObjectName("sortByNotebook")
self.gridLayout_2.addWidget(self.sortByNotebook, 5, 1, 1, 1)
self.label_indLayout = QtGui.QLabel(self.tab_2)
self.label_indLayout.setObjectName("label_indLayout")
self.gridLayout_2.addWidget(self.label_indLayout, 5, 0, 1, 1)
self.gridLayout_2.addWidget(self.label_indLayout, 6, 0, 1, 1)
self.listWidget_indLayout = QtGui.QListWidget(self.tab_2)
self.listWidget_indLayout.setMinimumSize(QtCore.QSize(0, 96))
self.listWidget_indLayout.setMaximumSize(QtCore.QSize(16777215, 96))
self.listWidget_indLayout.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.listWidget_indLayout.setDragDropMode(QtGui.QAbstractItemView.InternalMove)
self.listWidget_indLayout.setObjectName("listWidget_indLayout")
self.gridLayout_2.addWidget(self.listWidget_indLayout, 5, 1, 1, 1)
self.gridLayout_2.addWidget(self.listWidget_indLayout, 6, 1, 1, 1)
self.tabWidget.addTab(self.tab_2, "")
self.verticalLayout.addWidget(self.tabWidget)
self.webView = QtWebKit.QWebView(Dialog)
@@ -117,6 +124,7 @@ def retranslateUi(self, Dialog):
self.label_6.setText(QtGui.QApplication.translate("Dialog", "Black tray icon", None, QtGui.QApplication.UnicodeUTF8))
self.progressLabel.setText(QtGui.QApplication.translate("Dialog", "Launcher progress bar", None, QtGui.QApplication.UnicodeUTF8))
self.label_7.setText(QtGui.QApplication.translate("Dialog", "Search on the home lens", None, QtGui.QApplication.UnicodeUTF8))
self.label_8.setText(QtGui.QApplication.translate("Dialog", "Sort notes by notebook", None, QtGui.QApplication.UnicodeUTF8))
self.label_indLayout.setText(QtGui.QApplication.translate("Dialog", "Indicator Layout", None, QtGui.QApplication.UnicodeUTF8))
self.listWidget_indLayout.setToolTip(QtGui.QApplication.translate("Dialog", "<html><head/><body><p>Drag and drop items to change layout.</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), QtGui.QApplication.translate("Dialog", "Appearance", None, QtGui.QApplication.UnicodeUTF8))
@@ -135,13 +135,27 @@
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Sort notes by notebook</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QCheckBox" name="sortByNotebook">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_indLayout">
<property name="text">
<string>Indicator Layout</string>
</property>
</widget>
</item>
<item row="5" column="1">
<item row="6" column="1">
<widget class="QListWidget" name="listWidget_indLayout">
<property name="minimumSize">
<size>
@@ -3,7 +3,7 @@
from PySide.QtCore import Slot, QTranslator, QLocale, Signal, QSettings, QT_TRANSLATE_NOOP, QLibraryInfo
from PySide.QtGui import QApplication, QSystemTrayIcon, QMenu, QCursor
from PySide.QtNetwork import QNetworkProxyFactory
from everpad.basetypes import Note, NONE_ID, NONE_VAL
from everpad.basetypes import Note, NONE_ID, NONE_VAL, Notebook
from everpad.tools import get_provider, get_pad, print_version, resource_filename
from everpad.pad.editor import Editor
from everpad.pad.management import Management
@@ -41,10 +41,10 @@ def _activated(self, reason):
if reason == QSystemTrayIcon.Trigger:
self.menu.popup(QCursor().pos())
def _add_note(self, struct):
def _add_note(self, menu, struct):
note = Note.from_tuple(struct)
title = note.title[:40].replace('&', '&&')
self.menu.addAction(title, Slot()(
menu.addAction(title, Slot()(
partial(self.open, note=note)
))
@@ -77,13 +77,30 @@ def update(self):
dbus.Array([], signature='i'), 0,
20, Note.ORDER_UPDATED_DESC, 1,
)
notes = self.app.provider.find_notes(
'', dbus.Array([], signature='i'),
dbus.Array([], signature='i'), 0,
20 - len(pin_notes), Note.ORDER_UPDATED_DESC, 0,
)
sort_by_notebook = bool(int(
self.app.provider.get_settings_value('sort-by-notebook') or 0))
has_notes = False
if not sort_by_notebook:
notes = self.app.provider.find_notes(
'', dbus.Array([], signature='i'),
dbus.Array([], signature='i'), 0,
20 - len(pin_notes), Note.ORDER_UPDATED_DESC, 0,
)
has_notes = bool(notes)
else:
notebooks = self.app.provider.list_notebooks()
notes = {}
for notebook_struct in notebooks:
notebook = Notebook.from_tuple(notebook_struct)
_notes = self.app.provider.find_notes('', [notebook.id],
dbus.Array([], signature='i'), 0,
20 - len(pin_notes), Note.ORDER_UPDATED_DESC, 0,
)
notes[notebook] = _notes
if _notes:
has_notes = True
first_sync = not (
len(notes) + len(pin_notes) or self.app.provider.is_first_synced()
has_notes or len(pin_notes) or self.app.provider.is_first_synced()
)
status_syncing = self.app.provider.get_status() == STATUS_SYNC
if status_syncing and first_sync:
@@ -115,8 +132,15 @@ def update(self):
if not first_sync:
if len(menu_items[item]):
self.menu.addSeparator()
if item == 'notes' and sort_by_notebook:
for notebook in menu_items[item]:
sub_menu = self.menu.addMenu(notebook.name)
_notes = menu_items[item][notebook]
for struct in _notes:
self._add_note(sub_menu, struct)
continue
for struct in menu_items[item]:
self._add_note(struct)
self._add_note(self.menu, struct)
self.menu.addSeparator()
else:
action = self.menu.addAction(menu_items[item][0], menu_items[item][1])
@@ -119,6 +119,7 @@ def __init__(self, *args, **kwargs):
}
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()
@@ -184,6 +185,12 @@ def search_on_home_changed(self):
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():
@@ -208,6 +215,9 @@ def update_tabs(self):
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):
@@ -49,6 +49,7 @@ def on_authenticated(self, token):
@Slot()
def on_remove_authenticated(self):
self.sync_thread.quit()
self.sync_thread.update_count = 0
set_auth_token('')
session = get_db_session()
session.query(models.Note).delete(

0 comments on commit 0b7e448

Please sign in to comment.