]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiInfo.cpp
Few string fixes from Dan.
[lyx.git] / src / frontends / qt / GuiInfo.cpp
1 /**
2  * \file GuiInfo.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Abdelrazak Younes
7  * \author Jürgen Spitzmüller
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiInfo.h"
15
16 #include "qt_helpers.h"
17
18 #include "Buffer.h"
19 #include "buffer_funcs.h"
20 #include "BufferParams.h"
21 #include "BufferView.h"
22 #include "Cursor.h"
23 #include "Language.h"
24
25 #include "GuiApplication.h"
26 #include "GuiView.h"
27
28 #include "insets/InsetInfo.h"
29
30 #include "support/debug.h"
31 #include "support/gettext.h"
32 #include "support/lstrings.h"
33
34
35 using namespace std;
36 using namespace lyx::support;
37
38 namespace lyx {
39 namespace frontend {
40
41 /////////////////////////////////////////////////////////////////
42 //
43 // GuiInfo
44 //
45 /////////////////////////////////////////////////////////////////
46
47 char const * info_types[] =
48 { "date",
49   "moddate",
50   "fixdate",
51   "time",
52   "modtime",
53   "fixtime",
54   "buffer",
55   "vcs",
56   "package",
57   "textclass",
58   "shortcut",
59   "shortcuts",
60   "menu",
61   "l7n",
62   "icon",
63   "lyxrc",
64   "lyxinfo",
65   ""
66 };
67
68 // GUI names (in combo)
69 char const * info_types_gui[] =
70 { N_("Date (current)"),// date
71   N_("Date (last modification of document)"),// moddate
72   N_("Date (fixed)"),// fixdate
73   N_("Time (current)"),// time
74   N_("Time (last modification of document)"),// modtime
75   N_("Time (fixed)"),// fixtime
76   N_("Document Information"),// buffer
77   N_("Version Control Information"),// vcs
78   N_("LaTeX Package Availability"),// package
79   N_("LaTeX Class Availability"),// textclass
80   N_("Last Assigned Keyboard Shortcut"),// shortcut
81   N_("All Assigned Keyboard Shortcuts"),// shortcuts
82   N_("LyX Menu Location"),// menu
83   N_("Localized GUI String"),// l7n
84   N_("LyX Toolbar Icon"),// icon
85   N_("LyX Preferences Entry"),// lyxrc
86   N_("LyX Application Information"),// lyxinfo
87   ""
88 };
89
90 // Line edit label
91 char const * info_name_gui[] =
92 { N_("Custom Format"),// date
93   N_("Custom Format"),// moddate
94   N_("Custom Format"),// fixdate
95   N_("Custom Format"),// time
96   N_("Custom Format"),// modtime
97   N_("Custom Format"),// fixtime
98   N_("Not Applicable"),// buffer
99   N_("Not Applicable"),// vcs
100   N_("Package Name"),// package
101   N_("Class Name"),// textclass
102   N_("LyX Function"),// shortcut
103   N_("LyX Function"),// shortcuts
104   N_("LyX Function"),// menu
105   N_("English String"),// l7n
106   N_("LyX Function"),// icon
107   N_("Preferences Key"),// lyxrc
108   N_("Not Applicable"),// lyxinfo
109   N_("Not Applicable"),// unknown
110   ""
111 };
112
113 // Line edit tooltip
114 char const * info_tooltip[] =
115 { N_("Enter date format specification, using the following placeholders:\n"
116      "* d: day as number without a leading zero\n"
117      "* dd: day as number with a leading zero\n"
118      "* ddd: abbreviated localized day name\n"
119      "* dddd: long localized day name\n"
120      "* M: month as number without a leading zero\n"
121      "* MM: month as number with a leading zero\n"
122      "* MMM: abbreviated localized month name\n"
123      "* MMMM: long localized month name\n"
124      "* yy: year as two digit number\n"
125      "* yyyy: year as four digit number"),// date
126   N_("Enter date format specification, using the following placeholders:\n"
127      "* d: day as number without a leading zero\n"
128      "* dd: day as number with a leading zero\n"
129      "* ddd: abbreviated localized day name\n"
130      "* dddd: long localized day name\n"
131      "* M: month as number without a leading zero\n"
132      "* MM: month as number with a leading zero\n"
133      "* MMM: abbreviated localized month name\n"
134      "* MMMM: long localized month name\n"
135      "* yy: year as two digit number\n"
136      "* yyyy: year as four digit number"),// moddate
137   N_("Enter date format specification, using the following placeholders:\n"
138      "* d: day as number without a leading zero\n"
139      "* dd: day as number with a leading zero\n"
140      "* ddd: abbreviated localized day name\n"
141      "* dddd: long localized day name\n"
142      "* M: month as number without a leading zero\n"
143      "* MM: month as number with a leading zero\n"
144      "* MMM: abbreviated localized month name\n"
145      "* MMMM: long localized month name\n"
146      "* yy: year as two digit number\n"
147      "* yyyy: year as four digit number"),// fixdate
148   N_("Enter time format specification, using the following placeholders:\n"
149      "* h: the hour without a leading zero (1-12 in AM/PM)\n"
150      "* hh: the hour with a leading zero (01-12 in AM/PM)\n"
151      "* H: the hour without a leading zero (0-23)\n"
152      "* HH: the hour with a leading zero (00-23)\n"
153      "* m: the minute without a leading zero\n"
154      "* mm: the minute with a leading zero\n"
155      "* s: the second without a leading zero\n"
156      "* ss: the second with a leading zero\n"
157      "* z: the milliseconds without leading zeroes\n"
158      "* zzz: the milliseconds with leading zeroes\n"
159      "* AP or A: use AM/PM display ('AM'/'PM')\n"
160      "* ap or a: use am/pm display ('am'/'pm')\n"
161      "* t: the timezone (e.g. CEST)"),// time
162   N_("Enter time format specification, using the following placeholders:\n"
163      "* h: the hour without a leading zero (1-12 in AM/PM)\n"
164      "* hh: the hour with a leading zero (01-12 in AM/PM)\n"
165      "* H: the hour without a leading zero (0-23)\n"
166      "* HH: the hour with a leading zero (00-23)\n"
167      "* m: the minute without a leading zero\n"
168      "* mm: the minute with a leading zero\n"
169      "* s: the second without a leading zero\n"
170      "* ss: the second with a leading zero\n"
171      "* z: the milliseconds without leading zeroes\n"
172      "* zzz: the milliseconds with leading zeroes\n"
173      "* AP or A: use AM/PM display ('AM'/'PM')\n"
174      "* ap or a: use am/pm display ('am'/'pm')\n"
175      "* t: the timezone (e.g. CEST)"),// modtime
176   N_("Enter time format specification, using the following placeholders:\n"
177      "* h: the hour without a leading zero (1-12 in AM/PM)\n"
178      "* hh: the hour with a leading zero (01-12 in AM/PM)\n"
179      "* H: the hour without a leading zero (0-23)\n"
180      "* HH: the hour with a leading zero (00-23)\n"
181      "* m: the minute without a leading zero\n"
182      "* mm: the minute with a leading zero\n"
183      "* s: the second without a leading zero\n"
184      "* ss: the second with a leading zero\n"
185      "* z: the milliseconds without leading zeroes\n"
186      "* zzz: the milliseconds with leading zeroes\n"
187      "* AP or A: use AM/PM display ('AM'/'PM')\n"
188      "* ap or a: use am/pm display ('am'/'pm')\n"
189      "* t: the timezone (e.g. CEST)"),// fixtime
190   N_("Please select a valid type above"),// buffer
191   N_("Please select a valid type above"),// vcs
192   N_("Enter a LaTeX package name such as 'hyperref' (extension is optional). "
193      "The output will be 'Yes' (package available) or 'No' (package unavailable)."),// package
194   N_("Enter a LaTeX class name such as 'article' (extension is optional). "
195      "The output will be 'Yes' (class available) or 'No' (class unavailable)."),// textclass
196   N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. "
197      "The output is the most recently assigned keyboard shortcut for this function"),// shortcut
198   N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. "
199      "The output lists all possible keyboard shortcuts for this function"),// shortcuts
200   N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. "
201      "The output is the path to the function in the menu (using the current localization)."),// menu
202   N_("Enter a localizable English string from the LyX User Interface, including accelerator markup ('&' or '|') and trailing colons. "
203      "The output is the localized string (using the current localization); trailing colons and accelerator markup are stripped."),// l7n
204   N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. "
205      "The output is the toolbar icon for this function (using the active icon theme)."),// icon
206   N_("Enter a LyX preferences key such as 'bind_file'. See the proposed list for available entries. "
207      "The output is the current setting of this preference."),// lyxrc
208   N_("Please select a valid type above"),// lyxinfo
209   N_("Please select a valid type above"),// unknown
210   ""};
211
212
213 GuiInfo::GuiInfo(QWidget * parent) : InsetParamsWidget(parent)
214 {
215         setupUi(this);
216
217         typeCO->blockSignals(true);
218         for (int n = 0; info_types[n][0]; ++n)
219                 typeCO->addItem(qt_(info_types_gui[n]), info_types[n]);
220         typeCO->blockSignals(false);
221
222         connect(typeCO, SIGNAL(currentIndexChanged(int)), this, SLOT(updateArguments(int)));
223         connect(nameLE, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
224         connect(fixDateLE, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
225         connect(infoLW, SIGNAL(currentTextChanged(QString)), this, SIGNAL(changed()));
226 }
227
228
229 void GuiInfo::paramsToDialog(Inset const * inset)
230 {
231         InsetInfo const * ii = static_cast<InsetInfo const *>(inset);
232         params_ = ii->params();
233         QString const type = toqstr(params_.infoType());
234         QString name = toqstr(params_.name);
235         QString fixdate;
236         if (type == "fixdate" || type == "fixtime") {
237                 fixdate = name.section('@', 1, 1);
238                 name = name.section('@', 0, 0);
239                 if (!fixdate.isEmpty())
240                         fixDateLE->setText(fixdate);
241                 else {
242                         if (type == "fixdate")
243                                 fixDateLE->setText(QDate::currentDate().toString(Qt::ISODate));
244                         else
245                                 fixDateLE->setText(QTime::currentTime().toString(Qt::ISODate));
246                 }
247         }
248         typeCO->blockSignals(true);
249         nameLE->blockSignals(true);
250         nameLE->clear();
251         // The "unknown" item is only in the combo if we open
252         // the dialog from an unknown info. The user should not
253         // change a valid info to an unknown one.
254         int i = typeCO->findData("unknown");
255         if (i == -1 && type == "unknown")
256                 typeCO->addItem(qt_("Unknown"), toqstr("unknown"));
257         if (i != -1 && type != "unknown")
258                 typeCO->removeItem(i);
259         i = typeCO->findData(type);
260         typeCO->setCurrentIndex(i);
261         updateArguments(i);
262         int argindex = -1;
263         int customindex = 0;
264         for (int i = 0 ; i < infoLW->count() ; ++i) {
265                 if (infoLW->item(i)->data(Qt::UserRole).toString() == name)
266                         argindex = i;
267                 else if (infoLW->item(i)->data(Qt::UserRole).toString() == "custom")
268                         customindex = i;
269         }
270         if (argindex != -1)
271                 infoLW->setCurrentRow(argindex);
272         else {
273                 // Without this test, 'math-insert' (name) will replace 'math-insert '
274                 // in nameLE and effectively disallow the input of spaces after a LFUN.
275                 if (nameLE->text().trimmed() != name)
276                         nameLE->setText(name);
277                 infoLW->setCurrentRow(customindex);
278         }
279         typeCO->blockSignals(false);
280         nameLE->blockSignals(false);
281 }
282
283
284 docstring GuiInfo::dialogToParams() const
285 {
286         QString type =
287                 typeCO->itemData(typeCO->currentIndex()).toString();
288         QString name = infoLW->currentItem() ?
289                                 infoLW->currentItem()->data(Qt::UserRole).toString()
290                               : QString();
291         if (name == "custom")
292                 name = nameLE->text();
293         if (type == "fixdate" || type == "fixtime") {
294                 QString fd = fixDateLE->text();
295                 if (fd.isEmpty())
296                         fd = (type == "fixdate") ?
297                                         QDate::currentDate().toString(Qt::ISODate)
298                                       : QTime::currentTime().toString(Qt::ISODate);
299                 name += "@" + fd;
300         }
301         return qstring_to_ucs4(type + ' ' + name);
302 }
303
304
305 bool GuiInfo::initialiseParams(std::string const & sdata)
306 {
307         Language const * lang = languages.getLanguage(sdata);
308         if (!lang)
309                 return false;
310         params_.lang = lang;
311         updateArguments(typeCO->currentIndex());
312         return true;
313 }
314
315
316 void GuiInfo::updateArguments(int i)
317 {
318         if (i == -1)
319                 i = 0;
320
321         infoLW->clear();
322         BufferView const * bv = guiApp->currentView()->currentBufferView();
323         vector<pair<string,docstring>> args = params_.getArguments(const_cast<Buffer *>(&bv->buffer()),
324                                                                    info_types[i]);
325         for (auto const & p : args) {
326                 QListWidgetItem * li = new QListWidgetItem(toqstr(p.second));
327                 li->setData(Qt::UserRole, toqstr(p.first));
328                 if (p.first == "invalid")
329                         // non-selectable, disabled item!
330                         li->setFlags(Qt::NoItemFlags);
331                 if (p.first == "custom")
332                         li->setData(Qt::ToolTipRole, qt_("Enter a valid value below"));
333                 infoLW->addItem(li);
334         }
335         if (infoLW->count() > 0)
336                 infoLW->setCurrentRow(0);
337         changed();
338 }
339
340
341 bool GuiInfo::checkWidgets(bool readonly) const
342 {
343         nameLE->setReadOnly(readonly);
344         typeCO->setEnabled(!readonly);
345         nameLA->setText(qt_(info_name_gui[typeCO->currentIndex()]) + toqstr(":"));
346
347         QString const arg = infoLW->currentItem() ?
348                                 infoLW->currentItem()->data(Qt::UserRole).toString()
349                               : QString();
350
351         bool const type_enabled = (arg == "custom");
352         nameLA->setEnabled(type_enabled);
353         nameLE->setEnabled(type_enabled);
354         nameLE->setToolTip(qt_(info_tooltip[typeCO->currentIndex()]));
355
356         string const typestr = info_types[typeCO->currentIndex()];
357         bool const fixdate_enabled = (typestr == "fixdate" || typestr == "fixtime");
358         fixDateLE->setVisible(fixdate_enabled);
359         fixDateLA->setVisible(fixdate_enabled);
360         if (typestr == "fixdate") {
361                 fixDateLE->setToolTip(qt_("Here you can enter a fixed date (in ISO format: YYYY-MM-DD)"));
362                 fixDateLA->setText(qt_("&Fixed Date:"));
363         }
364         else if (typestr == "fixtime") {
365                 fixDateLE->setToolTip(qt_("Here you can enter a fixed time (in ISO format: hh:mm:ss)"));
366                 fixDateLA->setText(qt_("&Fixed Time:"));
367         }
368
369         if (!InsetParamsWidget::checkWidgets())
370                 return false;
371         return !arg.isEmpty() && (arg != "custom" || !nameLE->text().isEmpty());
372 }
373
374
375
376 } // namespace frontend
377 } // namespace lyx
378
379 #include "moc_GuiInfo.cpp"