1
# This file is part of the Frescobaldi project, http://www.frescobaldi.org/
3
# Copyright (c) 2008 - 2011 by Wilbert Berendsen
5
# This program is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU General Public License
7
# as published by the Free Software Foundation; either version 2
8
# of the License, or (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
# See http://www.gnu.org/licenses/ for more information.
21
Session dialog for named session stuff.
24
from __future__ import unicode_literals
27
from PyQt4.QtGui import (
28
QCheckBox, QDialog, QDialogButtonBox, QGridLayout, QLabel, QLineEdit,
29
QMessageBox, QVBoxLayout)
32
import widgets.listedit
33
import widgets.urlrequester
37
class SessionManagerDialog(QDialog):
38
def __init__(self, mainwindow):
39
super(SessionManagerDialog, self).__init__(mainwindow)
40
self.setWindowTitle(app.caption(_("Manage Sessions")))
41
layout = QVBoxLayout()
42
self.setLayout(layout)
44
self.sessions = SessionList(self)
45
layout.addWidget(self.sessions)
46
layout.addWidget(widgets.Separator())
48
self.buttons = b = QDialogButtonBox(self)
50
b.setStandardButtons(QDialogButtonBox.Help | QDialogButtonBox.Close)
51
b.rejected.connect(self.accept)
55
class SessionList(widgets.listedit.ListEdit):
56
"""Manage the list of sessions."""
58
names = sessions.sessionNames()
59
current = sessions.currentSession()
62
self.setCurrentRow(names.index(current))
64
def removeItem(self, item):
65
sessions.deleteSession(item.text())
66
super(SessionList, self).removeItem(item)
68
def openEditor(self, item):
69
name = SessionEditor(self).edit(item.text())
75
class SessionEditor(QDialog):
76
def __init__(self, parent=None):
77
super(SessionEditor, self).__init__(parent)
79
layout = QVBoxLayout()
80
self.setLayout(layout)
83
layout.addLayout(grid)
85
self.name = QLineEdit()
86
self.nameLabel = l = QLabel()
88
grid.addWidget(l, 0, 0)
89
grid.addWidget(self.name, 0, 1)
91
self.autosave = QCheckBox()
92
grid.addWidget(self.autosave, 1, 1)
94
self.basedir = widgets.urlrequester.UrlRequester()
95
self.basedirLabel = l = QLabel()
96
l.setBuddy(self.basedir)
97
grid.addWidget(l, 2, 0)
98
grid.addWidget(self.basedir, 2, 1)
100
layout.addWidget(widgets.Separator())
101
self.buttons = b = QDialogButtonBox(self)
103
b.setStandardButtons(QDialogButtonBox.Help | QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
104
b.accepted.connect(self.accept)
105
b.rejected.connect(self.reject)
106
app.translateUI(self)
108
def translateUI(self):
109
self.nameLabel.setText(_("Name:"))
110
self.autosave.setText(_("Always save the list of documents in this session"))
111
self.basedirLabel.setText(_("Base directory:"))
113
def load(self, name):
114
settings = sessions.sessionGroup(name)
115
self.autosave.setChecked(settings.value("autosave", True) not in (False, 'false'))
116
self.basedir.setPath(settings.value("basedir", ""))
119
def save(self, name):
120
settings = sessions.sessionGroup(name)
121
settings.setValue("autosave", self.autosave.isChecked())
122
settings.setValue("basedir", self.basedir.path())
126
self.autosave.setChecked(True)
127
self.basedir.setPath('')
130
def edit(self, name=None):
131
self._originalName = name
133
caption = _("Edit session: {name}").format(name=name)
134
self.name.setText(name)
137
caption = _("Edit new session")
141
self.setWindowTitle(app.caption(caption))
144
name = self.name.text()
145
if self._originalName and name != self._originalName:
146
sessions.renameSession(self._originalName, name)
150
def done(self, result):
151
if not result or self.validate():
152
super(SessionEditor, self).done(result)
155
"""Checks if the input is acceptable.
157
If this method returns True, the dialog is accepted when OK is clicked.
158
Otherwise a messagebox could be displayed, and the dialog will remain
161
name = self.name.text().strip()
162
self.name.setText(name)
165
QMessageBox.warning(self, app.caption(_("Warning")),
166
_("Please enter a session name."))
167
if self._originalName:
168
self.name.setText(self._originalName)
173
QMessageBox.warning(self, app.caption(_("Warning")),
174
_("Please do not use the name '{name}'.".format(name="none")))
177
elif self._originalName != name and name in sessions.sessionNames():
179
box = QMessageBox(QMessageBox.Warning, app.caption(_("Warning")),
180
_("Another session with the name {name} already exists.\n\n"
181
"Do you want to overwrite it?").format(name=name),
182
QMessageBox.Discard | QMessageBox.Cancel, self)
183
box.button(QMessageBox.Discard).setText(_("Overwrite"))
185
if result != QMessageBox.Discard: