1 /**************************************************************************
5 Copyright (C) 2010-2011 Heli Hyvättinen
7 This file is part of KitchenAlert.
9 Kitchen Alert is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 **************************************************************************/
24 #include "stickydialog.h"
25 #include <QVBoxLayout>
27 #include <QPushButton>
28 #include <QFileDialog>
31 StickyDialog::StickyDialog(QString defaultDirectory, QWidget *parent) :
34 defaultDirectory_ = defaultDirectory;
37 QVBoxLayout* pMainLayout = new QVBoxLayout(this);
40 QStringList stickies = settings.value("sticky").toStringList();
42 // stickies.append("Test String");
44 pStickiesModel_ = new QStringListModel;
45 pStickiesModel_->setStringList(stickies);
47 pStickiesView_ = new QListView;
48 pStickiesView_->setModel(pStickiesModel_);
49 pStickiesView_->setSelectionMode(QAbstractItemView::SingleSelection);
50 pMainLayout->addWidget(pStickiesView_);
52 QHBoxLayout * pButtonLayout = new QHBoxLayout;
53 pMainLayout->addLayout(pButtonLayout);
55 QPushButton * pAddButton = new QPushButton (tr("Add"));
56 connect(pAddButton,SIGNAL(clicked()),this,SLOT(add()));
57 pButtonLayout->addWidget(pAddButton);
59 QPushButton * pRemoveButton = new QPushButton(tr("Remove"));
60 connect(pRemoveButton,SIGNAL(clicked()),this,SLOT(remove()));
61 pButtonLayout->addWidget(pRemoveButton);
63 QPushButton * pOkButton = new QPushButton(tr("OK"));
64 connect (pOkButton,SIGNAL(clicked()),this,SLOT(accept()));
65 pButtonLayout->addWidget(pOkButton);
68 void StickyDialog::add()
70 QString startDirectory;
72 if (QFile(defaultDirectory_).exists())
74 startDirectory = defaultDirectory_;
78 startDirectory = "/home/user/";
79 qDebug () << "default save directory not found";
83 QString filename = QFileDialog::getOpenFileName(this,tr("KitchenAlert - Choose a timer to add to stickied"),startDirectory,tr("KitchenAlert timer files (*.kitchenalert)"));
85 if (filename.isEmpty()) // user cancelled the dialog
89 QStringList tempList = pStickiesModel_->stringList();
90 tempList.append(filename);
91 pStickiesModel_->setStringList(tempList);
95 void StickyDialog::remove()
97 QItemSelectionModel* pSelected = pStickiesView_->selectionModel();
98 QModelIndex index = pSelected->currentIndex(); //Only single selection allowed, so we only need to care about current item
101 if (!index.isValid())
102 return; //Nothing selected, nothing to remove...
104 pStickiesModel_->removeRows(index.row(),1);
108 QStringList StickyDialog::getStickyList()
110 return pStickiesModel_->stringList();