}
with open(constants._user_settings_, "w") as settingsFile:
simplejson.dump(settings, settingsFile)
+ self._mainWindow.destroy()
@property
def fullscreenAction(self):
if self._child is not None:
self._child.clear()
- def refresh(self):
+ def refresh(self, force=True):
if self._child is not None:
- self._child.refresh()
+ self._child.refresh(force)
class Dialpad(object):
def clear(self):
pass
- def refresh(self):
+ def refresh(self, force = True):
pass
def _generate_key_button(self, center, letters):
def clear(self):
self._itemView.clear()
- def refresh(self):
- self._session.update_history()
+ def refresh(self, force=True):
+ self._session.update_history(force)
def _populate_items(self):
self._itemStore.clear()
def clear(self):
self._itemView.clear()
- def refresh(self):
- self._session.update_messages()
+ def refresh(self, force=True):
+ self._session.update_messages(force)
def _populate_items(self):
self._itemStore.clear()
def clear(self):
self._itemView.clear()
- def refresh(self):
- self._session.update_contacts()
+ def refresh(self, force=True):
+ self._session.update_contacts(force)
def _populate_items(self):
self._itemStore.clear()
def __init__(self, parent, app):
self._fsContactsPath = os.path.join(constants._data_path_, "contacts")
self._app = app
- self._session = session.Session()
+ self._session = session.Session(constants._data_path_)
self._session.error.connect(self._on_session_error)
self._session.loggedIn.connect(self._on_login)
self._session.loggedOut.connect(self._on_logout)
child.close()
self._window.close()
+ def destroy(self):
+ self._session.logout()
+
def set_fullscreen(self, isFullscreen):
if isFullscreen:
self._window.showFullScreen()
if not self._tabsContents[index].has_child():
tab = self._TAB_CLASS[index](self._app, self._session, self._errorLog)
self._tabsContents[index].set_child(tab)
- self._tabsContents[index].refresh()
+ self._tabsContents[index].refresh(force=False)
@QtCore.pyqtSlot(str)
@misc_utils.log_exception(_moduleLogger)
@misc_utils.log_exception(_moduleLogger)
def _on_refresh(self, checked = True):
index = self._tabWidget.currentIndex()
- self._tabsContents[index].refresh()
+ self._tabsContents[index].refresh(force=True)
@QtCore.pyqtSlot()
@QtCore.pyqtSlot(bool)
import time
import logging
+try:
+ import cPickle
+ pickle = cPickle
+except ImportError:
+ import pickle
+
from PyQt4 import QtCore
from util import qore_utils
from util import concurrent
+from util import misc as misc_utils
+import constants
from backends import gv_backend
LOGGINGIN_STATE = "logging in"
LOGGEDIN_STATE = "logged in"
+ _OLDEST_COMPATIBLE_FORMAT_VERSION = misc_utils.parse_version("1.2.0")
+
_LOGGEDOUT_TIME = -1
_LOGGINGIN_TIME = 0
self._loggedInTime = self._LOGGEDOUT_TIME
self.clear()
- def update_contacts(self):
+ def update_contacts(self, force = True):
+ if not force and self._contacts:
+ return
le = concurrent.AsyncLinearExecution(self._pool, self._update_contacts)
self._perform_op_while_loggedin(le)
def get_contacts(self):
return self._contacts
- def update_messages(self):
+ def update_messages(self, force = True):
+ if not force and self._messages:
+ return
le = concurrent.AsyncLinearExecution(self._pool, self._update_messages)
self._perform_op_while_loggedin(le)
def get_messages(self):
return self._messages
- def update_history(self):
+ def update_history(self, force = True):
+ if not force and self._history:
+ return
le = concurrent.AsyncLinearExecution(self._pool, self._update_history)
self._perform_op_while_loggedin(le)
finalState = self.LOGGEDIN_STATE
self.loggedIn.emit()
if oldUsername != self._username:
- self._load_from_cache()
- loginOps = self._loginOps[:]
+ needOps = not self._load()
+ else:
+ needOps = True
+ if needOps:
+ loginOps = self._loginOps[:]
+ else:
+ loginOps = []
del self._loginOps[:]
for asyncOp in loginOps:
asyncOp.start()
finally:
self.stateChange.emit(finalState)
- def _load_from_cache(self):
+ def _load(self):
updateContacts = len(self._contacts) != 0
updateMessages = len(self._messages) != 0
updateHistory = len(self._history) != 0
self._dnd = False
self._callback = ""
+ loadedFromCache = self._load_from_cache()
+ if loadedFromCache:
+ updateContacts = True
+ updateMessages = True
+ updateHistory = True
+
if updateContacts:
self.contactsUpdated.emit()
if updateMessages:
if oldCallback != self._callback:
self.callbackNumberChanged.emit(self._callback)
+ return loadedFromCache
+
+ def _load_from_cache(self):
+ if self._cachePath is None:
+ return False
+ cachePath = os.path.join(self._cachePath, "%s.cache" % self._username)
+
+ try:
+ with open(cachePath, "rb") as f:
+ dumpedData = pickle.load(f)
+ except (pickle.PickleError, IOError, EOFError, ValueError):
+ _moduleLogger.exception("Pickle fun loading")
+ return False
+ except:
+ _moduleLogger.exception("Weirdness loading")
+ return False
+
+ (
+ version, build,
+ contacts, messages, history, dnd, callback
+ ) = dumpedData
+
+ if misc_utils.compare_versions(
+ self._OLDEST_COMPATIBLE_FORMAT_VERSION,
+ misc_utils.parse_version(version),
+ ) <= 0:
+ _moduleLogger.info("Loaded cache")
+ self._contacts = contacts
+ self._messages = messages
+ self._history = history
+ self._dnd = dnd
+ self._callback = callback
+ return True
+ else:
+ _moduleLogger.debug(
+ "Skipping cache due to version mismatch (%s-%s)" % (
+ version, build
+ )
+ )
+ return False
+
def _save_to_cache(self):
- # @todo
- pass
+ _moduleLogger.info("Saving cache")
+ if self._cachePath is None:
+ return
+ cachePath = os.path.join(self._cachePath, "%s.cache" % self._username)
+
+ try:
+ dataToDump = (
+ constants.__version__, constants.__build__,
+ self._contacts, self._messages, self._history, self._dnd, self._callback
+ )
+ with open(cachePath, "wb") as f:
+ pickle.dump(dataToDump, f, pickle.HIGHEST_PROTOCOL)
+ _moduleLogger.info("Cache saved")
+ except (pickle.PickleError, IOError):
+ _moduleLogger.exception("While saving")
def _clear_cache(self):
updateContacts = len(self._contacts) != 0