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