]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/util/comboutil.cpp
This is the application of a patch from Ricardo. Includes a great qty of translation...
[bacula/bacula] / bacula / src / qt-console / util / comboutil.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2007-2008 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 John Walker.
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 <QComboBox>
39 #include <QString>
40 #include <QStringList>
41 #include "bat.h"
42 #include "comboutil.h"
43
44 static const QString QS_ANY(QObject::tr("Any"));
45
46
47 /* selects value val on combo, if exists */
48 void comboSel(QComboBox *combo, const QString &val)
49 {
50   int index = combo->findText(val, Qt::MatchExactly);
51   if (index != -1) {
52      combo->setCurrentIndex(index);
53   }
54 }
55
56 /* if the combo has selected something different from "Any" uses the selection
57  * to build a condition on field fldname and adds it to the condition list */
58 void comboCond(QStringList &cndlist, const QComboBox *combo, const char *fldname)
59 {
60    int index = combo->currentIndex();
61    if (index != -1 && combo->itemText(index) != QS_ANY) {
62       cndlist.append( QString("%1='%2'").arg(fldname).arg(combo->itemText(index)) );
63    }
64 }
65
66
67 /* boolean combo (yes/no) */
68 void boolComboFill(QComboBox *combo)
69 {
70    combo->addItem(QS_ANY, -1);
71    combo->addItem(QObject::tr("No"), 0);
72    combo->addItem(QObject::tr("Yes"), 1);
73 }
74
75 void boolComboCond(QStringList &cndlist, const QComboBox *combo, const char *fldname)
76 {
77    int index = combo->currentIndex();
78    if (index != -1 && combo->itemData(index).toInt() >= 0 ) {
79       QString cnd = combo->itemData(index).toString();
80       cndlist.append( QString("%1='%2'").arg(fldname).arg(cnd) );
81    }
82 }
83
84 /* backup level combo */
85 void levelComboFill(QComboBox *combo)
86 {
87    combo->addItem(QS_ANY);
88    combo->addItem(job_level_to_str(L_FULL), L_FULL);
89    combo->addItem(job_level_to_str(L_INCREMENTAL), L_INCREMENTAL);
90    combo->addItem(job_level_to_str(L_DIFFERENTIAL), L_DIFFERENTIAL);
91    combo->addItem(job_level_to_str(L_SINCE), L_SINCE);
92    combo->addItem(job_level_to_str(L_VERIFY_CATALOG), L_VERIFY_CATALOG);
93    combo->addItem(job_level_to_str(L_VERIFY_INIT), L_VERIFY_INIT);
94    combo->addItem(job_level_to_str(L_VERIFY_VOLUME_TO_CATALOG), L_VERIFY_VOLUME_TO_CATALOG);
95    combo->addItem(job_level_to_str(L_VERIFY_DISK_TO_CATALOG), L_VERIFY_DISK_TO_CATALOG);
96    combo->addItem(job_level_to_str(L_VERIFY_DATA), L_VERIFY_DATA);
97    /* combo->addItem(job_level_to_str(L_BASE), L_BASE);  base jobs ignored */ 
98 }
99
100 void levelComboCond(QStringList &cndlist, const QComboBox *combo, const char *fldname)
101 {
102    int index = combo->currentIndex();
103    if (index != -1 && combo->itemText(index) != QS_ANY ) {
104       QString cnd = combo->itemData(index).toChar();
105       cndlist.append( QString("%1='%2'").arg(fldname).arg(cnd) );
106    }
107 }
108