[qt4] persistent toolbar visibility (closes #109851)

We use QSettings that provides persistent platform-independent application settings to store toolbar visibility status.

In order to simplify the settings instanciation that requires the application identity we initiate the applicaiton settings once at the startup.

Note

We will remote the config entries toolbardif and toolbarrev later.

authorAlain Leufroy <alain.leufroy@logilab.fr>
changeset4859c72b5d9b
branchdefault
phasedraft
hiddenyes
parent revision#5c63ff427714 [qt] refactorize: move tree graph drawing into a dedicated mixin
child revision#a59086e4abf6 [qt] remove toolbar visibility config entries (closes #109851)
files modified by this revision
hgviewlib/qt4/application.py
hgviewlib/qt4/hgrepoviewer.py
# HG changeset patch
# User Alain Leufroy <alain.leufroy@logilab.fr>
# Date 1365784377 -7200
# Fri Apr 12 18:32:57 2013 +0200
# Node ID 4859c72b5d9b6273f4df90956061c50a0775371b
# Parent 5c63ff4277144537011bb96806c46ca3b3456cc9
[qt4] persistent toolbar visibility (closes #109851)

We use QSettings that provides persistent platform-independent
application settings to store toolbar visibility status.

In order to simplify the settings instanciation that requires the
application identity we initiate the applicaiton settings once at the
startup.

.. note:: We will remote the config entries ``toolbardif`` and
``toolbarrev`` later.

diff --git a/hgviewlib/qt4/application.py b/hgviewlib/qt4/application.py
@@ -20,11 +20,11 @@
1 
2  import sys
3 
4  from hgrepoviewer import FileViewer, FileDiffViewer, HgRepoViewer, ManifestViewer
5  from hgviewlib.application import HgViewApplication
6 -from PyQt4 import QtGui
7 +from PyQt4 import QtGui, QtCore
8 
9 
10 
11  class HgViewQtApplication(HgViewApplication):
12      """
@@ -48,10 +48,17 @@
13 
14          super(HgViewQtApplication, self).__init__(*args, **kwargs)
15 
16          self.app = app
17 
18 +    def _set_application_settings(self):
19 +        """Initiate the application settings. This allows to use the
20 +        default QSettings constructor."""
21 +        QtCore.QCoreApplication.setOrganizationName("logilab")
22 +        QtCore.QCoreApplication.setOrganizationDomain("logilab.org")
23 +        QtCore.QCoreApplication.setApplicationName("hgview")
24 +
25      def exec_(self):
26          self.viewer.show()  #pylint: disable=E1103
27          if '--profile' in sys.argv or '--time' in sys.argv:
28              return 0
29          return self.app.exec_()
diff --git a/hgviewlib/qt4/hgrepoviewer.py b/hgviewlib/qt4/hgrepoviewer.py
@@ -9,10 +9,11 @@
30  Main Qt4 application for hgview
31  """
32  import sys, os
33  import re
34  import errno
35 +from functools import partial
36 
37  from PyQt4 import QtCore, QtGui, Qsci
38 
39  from mercurial import ui, hg
40  from mercurial import util
@@ -221,10 +222,36 @@
41          # rev mod toolbar
42          if self.textview_header.rst_action is not None:
43              self.toolBar_rev.addAction(self.textview_header.rst_action)
44          self.toolBar_rev.setVisible(self.cfg.getToolBarRevAtStartup())
45 
46 +        self.handle_toolbar_visibility()
47 +
48 +    def handle_toolbar_visibility(self):
49 +        """ set toolbar visibility from persitent settings and handle
50 +        visibility toggleling"""
51 +        toolbars = (self.toolBar_file,
52 +                    self.toolBar_edit,
53 +                    self.toolBar_treefilters,
54 +                    self.toolBar_diff,
55 +                    self.toolBar_rev,
56 +                    self.toolBar_help)
57 +        settings = QtCore.QSettings()
58 +        for toolbar in toolbars:
59 +            entryname = '%s/%s/visible' % (self.objectName(), toolbar.objectName())
60 +            # bring back persistent status
61 +            status = settings.value(entryname)
62 +            if status.isNull():
63 +                status = True
64 +            else:
65 +                status = status.toBool()
66 +            toolbar.setVisible(status)
67 +            # update settings on visibility toggleling
68 +            toolbar.toggleViewAction().toggled[bool].connect(
69 +                partial(settings.setValue, entryname)
70 +            )
71 +
72      def createActions(self):
73          # main window actions (from .ui file)
74          connect(self.actionOpen_repository, SIGNAL('triggered()'),
75                  self.open_repository)
76          connect(self.actionRefresh, SIGNAL('triggered()'),