File indexing completed on 2024-07-21 12:17:32

0001 //
0002 // C++ Implementation: converterdialog
0003 //
0004 // Description: Converter Dialog.
0005 //
0006 /*
0007 Copyright 2008-2011 Tomas Mecir <kmuddy@kmuddy.com>
0008 
0009 This program is free software; you can redistribute it and/or
0010 modify it under the terms of the GNU General Public License as
0011 published by the Free Software Foundation; either version 2 of 
0012 the License, or (at your option) any later version.
0013 
0014 This program is distributed in the hope that it will be useful,
0015 but WITHOUT ANY WARRANTY; without even the implied warranty of
0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017 GNU General Public License for more details.
0018 
0019 You should have received a copy of the GNU General Public License
0020 along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021 */
0022 
0023 #include "converterdialog.h"
0024 
0025 #include <KLocalizedString>
0026 
0027 #include <QDialogButtonBox>
0028 #include <QLabel>
0029 #include <QTreeWidget>
0030 #include <QVBoxLayout>
0031 
0032 struct cConverterDialog::Private {
0033   QTreeWidget *tree;
0034 };
0035 
0036 cConverterDialog::cConverterDialog (QWidget *parent) : QDialog (parent)
0037 {
0038   d = new Private;
0039 
0040   resize (QSize (500, 400));
0041   setWindowTitle (i18n ("Profile Converter"));
0042 
0043   QDialogButtonBox *buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
0044 
0045   //create main dialog's widget
0046   QWidget *page = new QWidget (this);
0047   QVBoxLayout *layout = new QVBoxLayout (page);
0048 
0049   QLabel *label = new QLabel (i18n ("Pick profiles that you would like to convert and press Ok. This tool will create a new profile containing the information from the chosen profiles. Existing profiles will not be overwritten, even if they have the same name. The old profiles will be kept intact."), this);
0050   label->setWordWrap (true);
0051   
0052   d->tree = new QTreeWidget (page);
0053   d->tree->setColumnCount (2);
0054   d->tree->setHeaderLabels (QStringList() << i18n ("Name") << i18n ("Path"));
0055   d->tree->setRootIsDecorated (false);
0056   d->tree->setUniformRowHeights (true);
0057   d->tree->setItemsExpandable (false);
0058 
0059   layout->addWidget (label);
0060   layout->addWidget (d->tree);
0061   layout->addWidget (buttons);
0062 }
0063 
0064 cConverterDialog::~cConverterDialog ()
0065 {
0066   delete d;
0067 }
0068 
0069 bool cConverterDialog::display (std::list<ConversionDialogItem *> items)
0070 {
0071   d->tree->clear ();
0072   std::list<ConversionDialogItem *>::iterator it;
0073   for (it = items.begin(); it != items.end(); ++it) {
0074     QTreeWidgetItem *item = new QTreeWidgetItem;
0075     item->setText (0, (*it)->name);
0076     item->setText (1, (*it)->path);
0077     item->setFlags (Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
0078     item->setCheckState (0, Qt::Unchecked);
0079     d->tree->addTopLevelItem (item);
0080   }
0081 
0082   // execute the dialog
0083   if (!exec()) return false;
0084 
0085   // update the checked flags
0086   int idx = 0;
0087   QTreeWidgetItem *root = d->tree->invisibleRootItem ();
0088   for (it = items.begin(); it != items.end(); ++it) {
0089     QTreeWidgetItem *item = root->child (idx);
0090     (*it)->convert = (item->checkState(0) == Qt::Checked);
0091     ++idx;
0092   }
0093   return true;
0094 }
0095 
0096 #include "moc_converterdialog.cpp"