Rules file now works with publisher wizard again
[kitchenalert] / src / stickydialog.cpp
1 /**************************************************************************
2
3         KitchenAlert
4
5         Copyright (C) 2010-2011  Heli Hyvättinen
6
7         This file is part of KitchenAlert.
8
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.
13
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.
18
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/>.
21
22 **************************************************************************/
23
24 #include "stickydialog.h"
25 #include <QVBoxLayout>
26 #include <QSettings>
27 #include <QPushButton>
28 #include <QFileDialog>
29 #include <QDebug>
30
31 StickyDialog::StickyDialog(QString defaultDirectory, QWidget *parent) :
32     QDialog(parent)
33 {
34     defaultDirectory_ = defaultDirectory;
35
36
37     QVBoxLayout* pMainLayout = new QVBoxLayout(this);
38
39     QSettings settings;
40     QStringList stickies = settings.value("sticky").toStringList();
41
42 //    stickies.append("Test String");
43
44     pStickiesModel_ = new QStringListModel;
45     pStickiesModel_->setStringList(stickies);
46
47     pStickiesView_ = new QListView;
48     pStickiesView_->setModel(pStickiesModel_);
49     pStickiesView_->setSelectionMode(QAbstractItemView::SingleSelection);
50     pMainLayout->addWidget(pStickiesView_);
51
52     QHBoxLayout * pButtonLayout = new QHBoxLayout;
53     pMainLayout->addLayout(pButtonLayout);
54
55     QPushButton *  pAddButton = new QPushButton (tr("Add"));
56     connect(pAddButton,SIGNAL(clicked()),this,SLOT(add()));
57     pButtonLayout->addWidget(pAddButton);
58
59     QPushButton * pRemoveButton = new QPushButton(tr("Remove"));
60     connect(pRemoveButton,SIGNAL(clicked()),this,SLOT(remove()));
61     pButtonLayout->addWidget(pRemoveButton);
62
63     QPushButton * pOkButton = new QPushButton(tr("OK"));
64     connect (pOkButton,SIGNAL(clicked()),this,SLOT(accept()));
65     pButtonLayout->addWidget(pOkButton);
66 }
67
68 void StickyDialog::add()
69 {
70     QString startDirectory;
71
72     if (QFile(defaultDirectory_).exists())
73     {
74         startDirectory = defaultDirectory_;
75     }
76     else
77     {
78         startDirectory = "/home/user/";
79         qDebug () << "default save directory not found";
80     }
81
82
83     QString filename = QFileDialog::getOpenFileName(this,tr("KitchenAlert - Choose a timer to add to stickied"),startDirectory,tr("KitchenAlert timer files (*.kitchenalert)"));
84
85     if (filename.isEmpty()) // user cancelled the dialog
86         return;
87
88
89     QStringList tempList = pStickiesModel_->stringList();
90     tempList.append(filename);
91     pStickiesModel_->setStringList(tempList);
92
93 }
94
95 void StickyDialog::remove()
96 {
97     QItemSelectionModel* pSelected = pStickiesView_->selectionModel();
98     QModelIndex index = pSelected->currentIndex(); //Only single selection allowed, so we only need to care about current item
99
100
101     if (!index.isValid())
102         return;         //Nothing selected, nothing to remove...
103
104     pStickiesModel_->removeRows(index.row(),1);
105
106 }
107
108 QStringList StickyDialog::getStickyList()
109 {
110     return pStickiesModel_->stringList();
111 }