1 /***************************************************************************
2 * Copyright (C) 2005-2007 by Tarek Saidi *
3 * tarek.saidi@arcor.de *
5 * Copyright (C) 2007 by Constantin "Dinosaur" Makshin *
6 * dinosaur-rus@users.sourceforge.net *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; version 2 of the License. *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22 ***************************************************************************/
26 KpxConfig::KpxConfig(const QString& filePath) : settings(filePath,QSettings::IniFormat){
28 if (settings.contains("Options/GroupTreeRestore") && !settings.contains("Options/GroupTreeState")){
29 switch (settings.value("Options/GroupTreeRestore",1).toInt()){
31 setGroupTreeState(RestoreLast);
35 setGroupTreeState(DoNothing);
39 setGroupTreeState(ExpandAll);
41 settings.remove("Options/GroupTreeRestore");
43 if (urlCmd()=="<<default>>")
47 #ifdef GLOBAL_AUTOTYPE
48 Shortcut KpxConfig::globalShortcut(){
50 s.key = settings.value("Options/GlobalShortcutKey",0).toUInt();
51 QBitArray mods = settings.value("Options/GlobalShortcutMods",QBitArray(5)).toBitArray();
54 s.ctrl = mods.testBit(0);
55 s.shift = mods.testBit(1);
56 s.alt = mods.testBit(2);
57 s.altgr = mods.testBit(3);
58 s.win = mods.testBit(4);
63 void KpxConfig::setGlobalShortcut(const Shortcut& s){
64 settings.setValue("Options/GlobalShortcutKey", s.key);
66 mods.setBit(0, s.ctrl);
67 mods.setBit(1, s.shift);
68 mods.setBit(2, s.alt);
69 mods.setBit(3, s.altgr);
70 mods.setBit(4, s.win);
71 settings.setValue("Options/GlobalShortcutMods", mods);
75 unsigned KpxConfig::fileDlgHistorySize(){
76 settings.beginGroup("FileDlgHistory");
77 unsigned res=static_cast<unsigned>(settings.childKeys().size());
82 QColor KpxConfig::stringToColor(const QString& str){
83 QStringList ints=str.split(',');
86 res.setRed(ints.at(0).toInt());
88 res.setGreen(ints.at(1).toInt());
90 res.setBlue(ints.at(2).toInt());
94 QBitArray KpxConfig::stringToBitArray(const QString& str, unsigned count){
95 QBitArray res(static_cast<int>(count));
96 if (static_cast<unsigned>(str.length())<count)
97 count=static_cast<unsigned>(str.length());
98 for (int i=0;i<static_cast<int>(count);i++){
100 if ((c=='1') || (c=='t') || (c=='y'))
106 KpxConfig::GrpTreeState KpxConfig::stringToGrpTreeState(const QString& str){
107 GrpTreeState res=ExpandAll;
108 if (!str.compare("Restore",Qt::CaseInsensitive))
110 else if (!str.compare("None",Qt::CaseInsensitive))
115 QList<int> KpxConfig::stringToIntArray(const QString& str, unsigned count){
116 QStringList ints=str.split(',');
119 intsCount=qMin(static_cast<unsigned>(ints.count()),count);
120 for (i=0;i<intsCount;i++)
121 res.append(ints.at(i).toInt());
127 KpxConfig::IntegrPluginType KpxConfig::stringToIntegrPluginType(const QString& str){
128 IntegrPluginType res=NoIntegr;
129 if (!str.compare("KDE",Qt::CaseInsensitive))
131 else if (!str.compare("Gnome",Qt::CaseInsensitive))
136 tKeyType KpxConfig::stringToKeyType(const QString& str){
137 tKeyType res=PASSWORD;
138 if (!str.compare("KeyFile",Qt::CaseInsensitive))
140 else if (!str.compare("Composite",Qt::CaseInsensitive))
145 QString KpxConfig::bitArrayToString(const QBitArray& bitArray){
147 for (int i=0;i<bitArray.count();i++)
148 res.append(QString::number(bitArray.at(i)?1:0));
152 QString KpxConfig::grpTreeStateToString(GrpTreeState grpTreeState){
154 switch (grpTreeState){
169 QString KpxConfig::intArrayToString(const QList<int>& intArray){
171 if (!intArray.isEmpty())
173 res.setNum(intArray.first());
174 for (int i=1;i<intArray.count();i++)
175 res.append(QString(",%1").arg(intArray.at(i)));
180 QString KpxConfig::integrPluginTypeToString(IntegrPluginType integrPluginType){
182 switch (integrPluginType){
197 QString KpxConfig::keyTypeToString(tKeyType keyType){
214 QByteArray KpxConfig::mainWindowGeometry() {
215 QVariant var = settings.value("UI/MainWindowGeometry");
216 if (var.type() == QVariant::ByteArray)
217 return var.toByteArray();
222 QRect KpxConfig::dialogGeometry(const QWidget* widget){
223 Q_ASSERT(widget->parentWidget()!=NULL && widget->parentWidget()->window()!=NULL);
224 QSize size = settings.value(QString("UI/%1Size").arg(widget->objectName()),widget->size()).toSize();
225 QSize minSize = widget->minimumSize();
226 if (size.width() < minSize.width() || size.height() < minSize.height())
228 if (minSize.isNull() && widget->layout()!=NULL){
229 minSize = widget->layout()->minimumSize();
230 if (size.width() < minSize.width() || size.height() < minSize.height())
235 rect=QRect(QPoint(), size);
236 rect.moveCenter( widget->parentWidget()->window()->geometry().center() );
240 void KpxConfig::setDialogGeometry(const QWidget* widget){
241 settings.setValue(QString("UI/%1Size").arg(widget->objectName()),widget->size());
244 QString KpxConfig::detailViewTemplate(){
245 if (settings.contains("UI/DetailsView")){
246 return QString::fromUtf8( qUncompress(settings.value("UI/DetailsView").toByteArray()) );
249 return defaultDetailViewTemplate();
253 QString KpxConfig::defaultDetailViewTemplate(){
254 QFile templ(":/default-detailview.html");
255 templ.open(QIODevice::ReadOnly);
256 QString value=QString::fromUtf8(templ.readAll());
258 value.replace("Group",QCoreApplication::translate("DetailViewTemplate","Group"));
259 value.replace("Title",QCoreApplication::translate("DetailViewTemplate","Title"));
260 value.replace("Username",QCoreApplication::translate("DetailViewTemplate","Username"));
261 value.replace("Password",QCoreApplication::translate("DetailViewTemplate","Password"));
262 value.replace("URL",QCoreApplication::translate("DetailViewTemplate","URL"));
263 value.replace("Creation",QCoreApplication::translate("DetailViewTemplate","Creation"));
264 value.replace("Last Access",QCoreApplication::translate("DetailViewTemplate","Last Access"));
265 value.replace("Last Modification",QCoreApplication::translate("DetailViewTemplate","Last Modification"));
266 value.replace("Expiration",QCoreApplication::translate("DetailViewTemplate","Expiration"));
267 value.replace("Comment",QCoreApplication::translate("DetailViewTemplate","Comment"));
271 void KpxConfig::setDetailViewTemplate(const QString& value){
272 settings.setValue("UI/DetailsView", qCompress(value.toUtf8(),9) );