Skip to content

Commit

Permalink
#39: Implemented a dialog for asking user about sending usage statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
vlkv committed May 25, 2013
1 parent 4fdddf9 commit 8e1f4ad
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 11 deletions.
5 changes: 2 additions & 3 deletions reggata/data/repo_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import reggata.consts as consts
from reggata.user_config import UserConfig
from reggata.data.db_schema import Base, HistoryRec

from reggata.helpers import stringToBool

class RepoMgr(object):
'''
Expand All @@ -26,8 +26,7 @@ def __init__(self, path_to_repo):
raise Exception("Directory {} is not a repository base path."
.format(self.base_path))

engine_echo = bool(UserConfig().get("sqlalchemy.engine_echo") in
["True", "true", "TRUE", "1", "Yes", "yes", "YES"])
engine_echo = stringToBool(UserConfig().get("sqlalchemy.engine_echo"))

self.__engine = sqa.create_engine(\
"sqlite:///" + self.base_path + os.sep + consts.METADATA_DIR + os.sep + \
Expand Down
13 changes: 11 additions & 2 deletions reggata/gui/user_dialogs_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Created on 27.08.2012
@author: vvolkov
'''
from PyQt4 import QtCore
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import QMessageBox, QInputDialog, QFileDialog
from reggata.gui.user_dialog import UserDialog
from reggata.gui.change_user_password_dialog import ChangeUserPasswordDialog
Expand Down Expand Up @@ -71,7 +71,7 @@ def getExistingDirectory(self, gui, textMessageForUser):
return dirPath

def getSaveFileName(self, gui, textMessageForUser, fileFilter=""):
filename = QFileDialog.getSaveFileName(parent=gui, caption=textMessageForUser,
filename = QFileDialog.getSaveFileName(parent=gui, caption=textMessageForUser,
filter=fileFilter,
options=QFileDialog.DontConfirmOverwrite)
return filename
Expand Down Expand Up @@ -99,3 +99,12 @@ def execGetTextDialog(self, gui, dialogTitle, textMessageForUser, defaultText=""
text, isOk = QInputDialog.getText(
gui, dialogTitle, textMessageForUser, text=defaultText)
return (text, isOk)


def execGetYesNoAnswerDialog(self, gui, title, question):
return QtGui.QMessageBox.question(gui, title, question, QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)





4 changes: 4 additions & 0 deletions reggata/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ def is_none_or_empty(s):
return True if s == "" else False


def stringToBool(s):
return bool(s in ["True", "true", "TRUE", "1", "Yes", "yes", "YES"])


#TODO: Rename into isInternalPath() or isSubDirectoryOf() or isSubPathOf()
def is_internal(url, base_path):
'''
Expand Down
54 changes: 48 additions & 6 deletions reggata/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
'''
Copyright 2010 Vitaly Volkov
Expand All @@ -25,13 +24,16 @@
import sys
import codecs
import logging.config
import PyQt4.QtCore as QtCore
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import QApplication
from PyQt4.QtCore import QCoreApplication
import reggata.consts as consts
import reggata.helpers as hlp
from reggata.user_config import UserConfig
import reggata.reggata_dir_locator
import reggata.logging_default_conf as logging_default_conf
from reggata.gui.main_window import MainWindow
from gui.user_dialogs_facade import UserDialogsFacade


logger = logging.getLogger(consts.ROOT_LOGGER + "." + __name__)
Expand Down Expand Up @@ -64,18 +66,50 @@ def configureTranslations(app):

reggataDir = reggata.reggata_dir_locator.modulePath()
logger.debug("reggataDir is " + reggataDir)

isQmLoaded = qtr.load(qm_filename, os.path.join(reggataDir, "reggata", "locale"))
if not isQmLoaded:
isQmLoaded = qtr.load(qm_filename, os.path.join(reggataDir, "locale"))


if isQmLoaded:
QtCore.QCoreApplication.installTranslator(qtr)
else:
logger.warning("Cannot find translation file {}.".format(qm_filename))


def isReggataInstanceRegistered():
instanceId = UserConfig().get("reggata_instance_id")
return False if hlp.is_none_or_empty(instanceId) else True


def isUserGaveTheAnswerAboutSendStatistics():
sendStatistics = UserConfig().get("send_statistics")
return False if hlp.is_none_or_empty(sendStatistics) else True


def isSendStatisticsAllowed():
sendStatistics = UserConfig().get("send_statistics")
return hlp.stringToBool(sendStatistics)


def askUserAboutSendStatistics(mainWindow):
title = "Reggata"
question = QCoreApplication.translate("main", "Do you want to help make Reggata better by automatically sending usage statistics?", None, QCoreApplication.UnicodeUTF8)
res = UserDialogsFacade().execGetYesNoAnswerDialog(mainWindow, title, question)
sendStatistics = None
if res == QtGui.QMessageBox.Yes:
sendStatistics = True
elif res == QtGui.QMessageBox.No:
sendStatistics = False
if sendStatistics is not None:
UserConfig().store("send_statistics", sendStatistics)


def registerReggataInstance():
# TODO: implement
pass



def main():
configureConfigDir()
Expand All @@ -91,8 +125,16 @@ def main():

configureTranslations(app)

form = MainWindow()
form.show()
mw = MainWindow()
mw.show()

if not isReggataInstanceRegistered() and not isUserGaveTheAnswerAboutSendStatistics():
askUserAboutSendStatistics(mw)

if isSendStatisticsAllowed() and not isReggataInstanceRegistered():
registerReggataInstance()


app.exec_()
logger.info("========= Reggata finished =========")

Expand Down

0 comments on commit 8e1f4ad

Please sign in to comment.