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