[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>
changeset519b4a226b8c
branchdefault
phasepublic
hiddenno
parent revision#5c63ff427714 [qt] refactorize: move tree graph drawing into a dedicated mixin
child revision#7cee5f88daec [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 1365787252 -7200
# Fri Apr 12 19:20:52 2013 +0200
# Node ID 519b4a226b8ca3d801e762729dc0cf1763bec5e2
# 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      """
@@ -34,10 +34,15 @@
13      FileDiffViewer = FileDiffViewer
14      HgRepoViewer = HgRepoViewer
15      ManifestViewer = ManifestViewer
16 
17      def __init__(self, *args, **kwargs):
18 +        # Initiate the application settings.
19 +        # This allows to use the default QSettings constructor.
20 +        QtCore.QCoreApplication.setOrganizationName("logilab")
21 +        QtCore.QCoreApplication.setOrganizationDomain("logilab.org")
22 +        QtCore.QCoreApplication.setApplicationName("hgview")
23          # This import is critical for qt initialization (at least on Mac os X)
24          import hgviewlib.qt4.hgqv_rc
25          # make Ctrl+C works
26          import signal
27          signal.signal(signal.SIGINT, signal.SIG_DFL)
diff --git a/hgviewlib/qt4/hgrepoviewer.py b/hgviewlib/qt4/hgrepoviewer.py
@@ -9,10 +9,11 @@
28  Main Qt4 application for hgview
29  """
30  import sys, os
31  import re
32  import errno
33 +from functools import partial
34 
35  from PyQt4 import QtCore, QtGui, Qsci
36 
37  from mercurial import ui, hg
38  from mercurial import util
@@ -221,10 +222,40 @@
39          # rev mod toolbar
40          if self.textview_header.rst_action is not None:
41              self.toolBar_rev.addAction(self.textview_header.rst_action)
42          self.toolBar_rev.setVisible(self.cfg.getToolBarRevAtStartup())
43 
44 +        self._handle_toolbar_visibility()
45 +
46 +    def _handle_toolbar_visibility(self):
47 +        """Initial value and event hooking
48 +
49 +        This function read toolbar related persistent settings from QT API.
50 +        It also setup hooks on visibility changes so to make the setting
51 +        persistent.
52 +        """
53 +        toolbars = (self.toolBar_file,
54 +                    self.toolBar_edit,
55 +                    self.toolBar_treefilters,
56 +                    self.toolBar_diff,
57 +                    self.toolBar_rev,
58 +                    self.toolBar_help)
59 +        settings = QtCore.QSettings()
60 +        for toolbar in toolbars:
61 +            entryname = '%s/%s/visible' % (self.objectName(), toolbar.objectName())
62 +            # bring back persistent status
63 +            status = settings.value(entryname)
64 +            if status.isNull():
65 +                status = True
66 +            else:
67 +                status = status.toBool()
68 +            toolbar.setVisible(status)
69 +            # update settings on visibility toggleling
70 +            toolbar.toggleViewAction().toggled[bool].connect(
71 +                partial(settings.setValue, entryname)
72 +            )
73 +
74      def createActions(self):
75          # main window actions (from .ui file)
76          connect(self.actionOpen_repository, SIGNAL('triggered()'),
77                  self.open_repository)
78          connect(self.actionRefresh, SIGNAL('triggered()'),