[qt4] persistent toolbar visibility - remove configs (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.

Warning

config entries toolbarrev and toolbardiff are removed. These entries were used to define the default toolbar visibility. Now, they are useless as the default status are set in a more userfriendly way.

authorAlain Leufroy <alain.leufroy@logilab.fr>
changesetb9aa413b46c5
branchdefault
phasedraft
hiddenyes
parent revision#5c63ff427714 [qt] refactorize: move tree graph drawing into a dedicated mixin
child revision<not specified>
files modified by this revision
hgviewlib/config.py
hgviewlib/qt4/application.py
hgviewlib/qt4/hgrepoviewer.py
# HG changeset patch
# User Alain Leufroy <alain.leufroy@logilab.fr>
# Date 1365777841 -7200
# Fri Apr 12 16:44:01 2013 +0200
# Node ID b9aa413b46c5b17d7f73db3ac71e877b0a8661d0
# Parent 5c63ff4277144537011bb96806c46ca3b3456cc9
[qt4] persistent toolbar visibility - remove configs (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.

.. warning:: config entries ``toolbarrev`` and ``toolbardiff`` are
removed. These entries were used to define the default
toolbar visibility. Now, they are useless as the default
status are set in a more userfriendly way.

diff --git a/hgviewlib/config.py b/hgviewlib/config.py
@@ -282,24 +282,10 @@
1          mqhidetags: hide mq tags
2          """
3          return self._fromconfig('mqhidetags', default)
4 
5      @cached
6 -    def getToolBarRevAtStartup(self, default=True):
7 -        """
8 -        toolbarrev: show hidden changeset at startup
9 -        """
10 -        return bool(self._fromconfig('toolbarrev', default))
11 -
12 -    @cached
13 -    def getToolBarDiffAtStartup(self, default=True):
14 -        """
15 -        toolbardiff: show hidden changeset at startup
16 -        """
17 -        return bool(self._fromconfig('toolbardiff', default))
18 -
19 -    @cached
20      def getContentAtStartUp(self, default=True):
21          """
22          contentatstartup: show the content of changeset at startup (bottom part)
23          """
24          return bool(self._fromconfig('contentatstartup', default))
diff --git a/hgviewlib/qt4/application.py b/hgviewlib/qt4/application.py
@@ -20,11 +20,11 @@
25 
26  import sys
27 
28  from hgrepoviewer import FileViewer, FileDiffViewer, HgRepoViewer, ManifestViewer
29  from hgviewlib.application import HgViewApplication
30 -from PyQt4 import QtGui
31 +from PyQt4 import QtGui, QtCore
32 
33 
34 
35  class HgViewQtApplication(HgViewApplication):
36      """
@@ -48,10 +48,17 @@
37 
38          super(HgViewQtApplication, self).__init__(*args, **kwargs)
39 
40          self.app = app
41 
42 +    def _set_application_settings(self):
43 +        """Initiate the application settings. This allows to use the
44 +        default QSettings constructor."""
45 +        QtCore.QCoreApplication.setOrganizationName("logilab")
46 +        QtCore.QCoreApplication.setOrganizationDomain("logilab.org")
47 +        QtCore.QCoreApplication.setApplicationName("hgview")
48 +
49      def exec_(self):
50          self.viewer.show()  #pylint: disable=E1103
51          if '--profile' in sys.argv or '--time' in sys.argv:
52              return 0
53          return self.app.exec_()
diff --git a/hgviewlib/qt4/hgrepoviewer.py b/hgviewlib/qt4/hgrepoviewer.py
@@ -9,10 +9,11 @@
54  Main Qt4 application for hgview
55  """
56  import sys, os
57  import re
58  import errno
59 +from functools import partial
60 
61  from PyQt4 import QtCore, QtGui, Qsci
62 
63  from mercurial import ui, hg
64  from mercurial import util
@@ -214,16 +215,40 @@
65 
66          # diff mode toolbar
67          actions = self.textview_status.sci._actions
68          for action_name in ('diffmode', 'prev', 'next', 'show-big-file'):
69              self.toolBar_diff.addAction(actions[action_name])
70 -        self.toolBar_diff.setVisible(self.cfg.getToolBarDiffAtStartup())
71 
72          # rev mod toolbar
73          if self.textview_header.rst_action is not None:
74              self.toolBar_rev.addAction(self.textview_header.rst_action)
75 -        self.toolBar_rev.setVisible(self.cfg.getToolBarRevAtStartup())
76 +
77 +        self.handle_toolbar_visibility()
78 +
79 +    def handle_toolbar_visibility(self):
80 +        """ set toolbar visibility from persitent settings and handle
81 +        visibility toggleling"""
82 +        toolbars = (self.toolBar_file,
83 +                    self.toolBar_edit,
84 +                    self.toolBar_treefilters,
85 +                    self.toolBar_diff,
86 +                    self.toolBar_rev,
87 +                    self.toolBar_help)
88 +        settings = QtCore.QSettings()
89 +        for toolbar in toolbars:
90 +            entryname = '%s/%s/visible' % (self.objectName(), toolbar.objectName())
91 +            # bring back persistent status
92 +            status = settings.value(entryname)
93 +            if status.isNull():
94 +                status = True
95 +            else:
96 +                status = status.toBool()
97 +            toolbar.setVisible(status)
98 +            # update settings on visibility toggleling
99 +            toolbar.toggleViewAction().toggled[bool].connect(
100 +                partial(settings.setValue, entryname)
101 +            )
102 
103      def createActions(self):
104          # main window actions (from .ui file)
105          connect(self.actionOpen_repository, SIGNAL('triggered()'),
106                  self.open_repository)