1 #include "stickydialog.h"
8 StickyDialog::StickyDialog(QString defaultDirectory, QWidget *parent) :
11 defaultDirectory_ = defaultDirectory;
14 QVBoxLayout* pMainLayout = new QVBoxLayout(this);
17 QStringList stickies = settings.value("sticky").toStringList();
19 // stickies.append("Test String");
21 pStickiesModel_ = new QStringListModel;
22 pStickiesModel_->setStringList(stickies);
24 pStickiesView_ = new QListView;
25 pStickiesView_->setModel(pStickiesModel_);
26 pStickiesView_->setSelectionMode(QAbstractItemView::SingleSelection);
27 pMainLayout->addWidget(pStickiesView_);
29 QHBoxLayout * pButtonLayout = new QHBoxLayout;
30 pMainLayout->addLayout(pButtonLayout);
32 QPushButton * pAddButton = new QPushButton (tr("Add"));
33 connect(pAddButton,SIGNAL(clicked()),this,SLOT(add()));
34 pButtonLayout->addWidget(pAddButton);
36 QPushButton * pRemoveButton = new QPushButton(tr("Remove"));
37 connect(pRemoveButton,SIGNAL(clicked()),this,SLOT(remove()));
38 pButtonLayout->addWidget(pRemoveButton);
40 QPushButton * pOkButton = new QPushButton(tr("OK"));
41 connect (pOkButton,SIGNAL(clicked()),this,SLOT(accept()));
42 pButtonLayout->addWidget(pOkButton);
45 void StickyDialog::add()
47 QString startDirectory;
49 if (QFile(defaultDirectory_).exists())
51 startDirectory = defaultDirectory_;
55 startDirectory = "/home/user/";
56 qDebug () << "default save directory not found";
60 QString filename = QFileDialog::getOpenFileName(this,tr("KitchenAlert - Choose a timer to add to stickied"),startDirectory,tr("KitchenAlert timer files (*.kitchenalert)"));
62 if (filename.isEmpty()) // user cancelled the dialog
66 QStringList tempList = pStickiesModel_->stringList();
67 tempList.append(filename);
68 pStickiesModel_->setStringList(tempList);
72 void StickyDialog::remove()
74 QItemSelectionModel* pSelected = pStickiesView_->selectionModel();
75 QModelIndex index = pSelected->currentIndex(); //Only single selection allowed, so we only need to care about current item
79 return; //Nothing selected, nothing to remove...
81 pStickiesModel_->removeRows(index.row(),1);
85 QStringList StickyDialog::getStickyList()
87 return pStickiesModel_->stringList();