]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/util/comboutil.cpp
73db9613833042bf3ff4ad9dd04bb0bcaeed0c65
[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
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version two of the GNU General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28
29 /*
30  *   Version $Id$
31  *
32  *   ComboBox helper functions
33  *
34  *   Riccardo Ghetta, May 2008
35  *
36  */
37
38 #include "bat.h"
39 #include <QComboBox>
40 #include <QString>
41 #include <QStringList>
42 #include "fmtwidgetitem.h"
43 #include "comboutil.h"
44
45 static const QString QS_ANY(QObject::tr("Any"));
46
47
48 /* selects value val on combo, if exists */
49 void comboSel(QComboBox *combo, const QString &val)
50 {
51   int index = combo->findText(val, Qt::MatchExactly);
52   if (index != -1) {
53      combo->setCurrentIndex(index);
54   }
55 }
56
57 /* if the combo has selected something different from "Any" uses the selection
58  * to build a condition on field fldname and adds it to the condition list */
59 void comboCond(QStringList &cndlist, const QComboBox *combo, const char *fldname)
60 {
61    int index = combo->currentIndex();
62    if (index != -1 && combo->itemText(index) != QS_ANY) {
63       cndlist.append( QString("%1='%2'").arg(fldname).arg(combo->itemText(index)) );
64    }
65 }
66
67
68 /* boolean combo (yes/no) */
69 void boolComboFill(QComboBox *combo)
70 {
71    combo->addItem(QS_ANY, -1);
72    combo->addItem(QObject::tr("No"), 0);
73    combo->addItem(QObject::tr("Yes"), 1);
74 }
75
76 void boolComboCond(QStringList &cndlist, const QComboBox *combo, const char *fldname)
77 {
78    int index = combo->currentIndex();
79    if (index != -1 && combo->itemData(index).toInt() >= 0 ) {
80       QString cnd = combo->itemData(index).toString();
81       cndlist.append( QString("%1='%2'").arg(fldname).arg(cnd) );
82    }
83 }
84
85 /* backup level combo */
86 void levelComboFill(QComboBox *combo)
87 {
88    combo->addItem(QS_ANY);
89    combo->addItem(job_level_to_str(L_FULL), L_FULL);
90    combo->addItem(job_level_to_str(L_INCREMENTAL), L_INCREMENTAL);
91    combo->addItem(job_level_to_str(L_DIFFERENTIAL), L_DIFFERENTIAL);
92    combo->addItem(job_level_to_str(L_SINCE), L_SINCE);
93    combo->addItem(job_level_to_str(L_VERIFY_CATALOG), L_VERIFY_CATALOG);
94    combo->addItem(job_level_to_str(L_VERIFY_INIT), L_VERIFY_INIT);
95    combo->addItem(job_level_to_str(L_VERIFY_VOLUME_TO_CATALOG), L_VERIFY_VOLUME_TO_CATALOG);
96    combo->addItem(job_level_to_str(L_VERIFY_DISK_TO_CATALOG), L_VERIFY_DISK_TO_CATALOG);
97    combo->addItem(job_level_to_str(L_VERIFY_DATA), L_VERIFY_DATA);
98    /* combo->addItem(job_level_to_str(L_BASE), L_BASE);  base jobs ignored */
99 }
100
101 void levelComboCond(QStringList &cndlist, const QComboBox *combo, const char *fldname)
102 {
103    int index = combo->currentIndex();
104    if (index != -1 && combo->itemText(index) != QS_ANY ) {
105       QString cnd = combo->itemData(index).toChar();
106       cndlist.append( QString("%1='%2'").arg(fldname).arg(cnd) );
107    }
108 }
109
110 /* job status combo */
111 void jobStatusComboFill(QComboBox *combo)
112 {
113    static const char js[] = {
114                       JS_Terminated,
115                       JS_Created,
116                       JS_Running,
117                       JS_Blocked,
118                       JS_ErrorTerminated,
119                       JS_Error,
120                       JS_FatalError,
121                       JS_Differences,
122                       JS_Canceled,
123                       JS_WaitFD,
124                       JS_WaitSD,
125                       JS_WaitMedia,
126                       JS_WaitMount,
127                       JS_WaitStoreRes,
128                       JS_WaitJobRes,
129                       JS_WaitClientRes,
130                       JS_WaitMaxJobs,
131                       JS_WaitStartTime,
132                       JS_WaitPriority,
133                       JS_AttrDespooling,
134                       JS_AttrInserting,
135                       JS_DataDespooling,
136                       JS_DataCommitting,
137                       '\0'};
138
139    int pos;
140
141    combo->addItem(QS_ANY);
142    for (pos = 0 ; js[pos] != '\0' ; ++pos) {
143      combo->addItem(convertJobStatus( QString(js[pos]) ), js[pos]);
144    }
145 }
146
147 void jobStatusComboCond(QStringList &cndlist, const QComboBox *combo, const char *fldname)
148 {
149    int index = combo->currentIndex();
150    if (index != -1 && combo->itemText(index) != QS_ANY ) {
151       QString cnd = combo->itemData(index).toChar();
152       cndlist.append( QString("%1='%2'").arg(fldname).arg(cnd) );
153    }
154 }