]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/util/comboutil.cpp
cd78b93abc968c4d196086c0aaa71992dff9fbe7
[bacula/bacula] / bacula / src / qt-console / util / comboutil.cpp
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2015 Kern Sibbald
5    Copyright (C) 2007-2009 Free Software Foundation Europe e.V.
6
7    The original author of Bacula is Kern Sibbald, with contributions
8    from many others, a complete list can be found in the file AUTHORS.
9
10    You may use this file and others of this release according to the
11    license defined in the LICENSE file, which includes the Affero General
12    Public License, v3.0 ("AGPLv3") and some additional permissions and
13    terms pursuant to its AGPLv3 Section 7.
14
15    This notice must be preserved when any source code is 
16    conveyed and/or propagated.
17
18    Bacula(R) is a registered trademark of Kern Sibbald.
19 */
20
21 /*
22  *   ComboBox helper functions
23  *
24  *   Riccardo Ghetta, May 2008
25  *
26  */
27
28 #include "bat.h"
29 #include <QComboBox>
30 #include <QString>
31 #include <QStringList>
32 #include "fmtwidgetitem.h"
33 #include "comboutil.h"
34
35 static const QString QS_ANY(QObject::tr("Any"));
36
37
38 /* selects value val on combo, if exists */
39 void comboSel(QComboBox *combo, const QString &val)
40 {
41   int index = combo->findText(val, Qt::MatchExactly);
42   if (index != -1) {
43      combo->setCurrentIndex(index);
44   }
45 }
46
47 /* if the combo has selected something different from "Any" uses the selection
48  * to build a condition on field fldname and adds it to the condition list */
49 void comboCond(QStringList &cndlist, const QComboBox *combo, const char *fldname)
50 {
51    int index = combo->currentIndex();
52    if (index != -1 && combo->itemText(index) != QS_ANY) {
53       cndlist.append( QString("%1='%2'").arg(fldname).arg(combo->itemText(index)) );
54    }
55 }
56
57
58 /* boolean combo (yes/no) */
59 void boolComboFill(QComboBox *combo)
60 {
61    combo->addItem(QS_ANY, -1);
62    combo->addItem(QObject::tr("No"), 0);
63    combo->addItem(QObject::tr("Yes"), 1);
64 }
65
66 void boolComboCond(QStringList &cndlist, const QComboBox *combo, const char *fldname)
67 {
68    int index = combo->currentIndex();
69    if (index != -1 && combo->itemData(index).toInt() >= 0 ) {
70       QString cnd = combo->itemData(index).toString();
71       cndlist.append( QString("%1='%2'").arg(fldname).arg(cnd) );
72    }
73 }
74
75 /* backup level combo */
76 void levelComboFill(QComboBox *combo)
77 {
78    combo->addItem(QS_ANY);
79    combo->addItem(job_level_to_str(L_FULL), L_FULL);
80    combo->addItem(job_level_to_str(L_INCREMENTAL), L_INCREMENTAL);
81    combo->addItem(job_level_to_str(L_DIFFERENTIAL), L_DIFFERENTIAL);
82    combo->addItem(job_level_to_str(L_SINCE), L_SINCE);
83    combo->addItem(job_level_to_str(L_VERIFY_CATALOG), L_VERIFY_CATALOG);
84    combo->addItem(job_level_to_str(L_VERIFY_INIT), L_VERIFY_INIT);
85    combo->addItem(job_level_to_str(L_VERIFY_VOLUME_TO_CATALOG), L_VERIFY_VOLUME_TO_CATALOG);
86    combo->addItem(job_level_to_str(L_VERIFY_DISK_TO_CATALOG), L_VERIFY_DISK_TO_CATALOG);
87    combo->addItem(job_level_to_str(L_VERIFY_DATA), L_VERIFY_DATA);
88    /* combo->addItem(job_level_to_str(L_BASE), L_BASE);  base jobs ignored */
89 }
90
91 void levelComboCond(QStringList &cndlist, const QComboBox *combo, const char *fldname)
92 {
93    int index = combo->currentIndex();
94    if (index != -1 && combo->itemText(index) != QS_ANY ) {
95       QString cnd = combo->itemData(index).toChar();
96       cndlist.append( QString("%1='%2'").arg(fldname).arg(cnd) );
97    }
98 }
99
100 /* job status combo */
101 void jobStatusComboFill(QComboBox *combo)
102 {
103    static const char js[] = {
104                       JS_Terminated,
105                       JS_Created,
106                       JS_Running,
107                       JS_Blocked,
108                       JS_ErrorTerminated,
109                       JS_Error,
110                       JS_FatalError,
111                       JS_Differences,
112                       JS_Canceled,
113                       JS_WaitFD,
114                       JS_WaitSD,
115                       JS_WaitMedia,
116                       JS_WaitMount,
117                       JS_WaitStoreRes,
118                       JS_WaitJobRes,
119                       JS_WaitClientRes,
120                       JS_WaitMaxJobs,
121                       JS_WaitStartTime,
122                       JS_WaitPriority,
123                       JS_AttrDespooling,
124                       JS_AttrInserting,
125                       JS_DataDespooling,
126                       JS_DataCommitting,
127                       '\0'};
128
129    int pos;
130
131    combo->addItem(QS_ANY);
132    for (pos = 0 ; js[pos] != '\0' ; ++pos) {
133      combo->addItem(convertJobStatus( QString(js[pos]) ), js[pos]);
134    }
135 }
136
137 void jobStatusComboCond(QStringList &cndlist, const QComboBox *combo, const char *fldname)
138 {
139    int index = combo->currentIndex();
140    if (index != -1 && combo->itemText(index) != QS_ANY ) {
141       QString cnd = combo->itemData(index).toChar();
142       cndlist.append( QString("%1='%2'").arg(fldname).arg(cnd) );
143    }
144 }