2 * This file is part of Jenirok.
4 * Jenirok is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Jenirok is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Jenirok. If not, see <http://www.gnu.org/licenses/>.
19 #include <QtCore/QDateTime>
20 #include <QtCore/QDebug>
21 #include <QtGui/QLabel>
22 #include <QtGui/QHBoxLayout>
23 #include <QtGui/QVBoxLayout>
24 #include <QtGui/QMenuBar>
25 #include "logwindow.h"
27 LogWindow::LogWindow(QWidget* parent): QMainWindow(parent), list_(0)
29 setAttribute(Qt::WA_Maemo5StackedWindow);
30 setWindowTitle(tr("Incoming call log"));
31 menuBar()->addAction(tr("Clear log"), this, SLOT(clearLog()));
34 void LogWindow::setVisible(bool visible)
41 QMainWindow::setVisible(visible);
44 void LogWindow::loadLogItems()
48 list_ = new ListWidget(this);
49 setCentralWidget(list_);
50 connect(list_, SIGNAL(itemClicked(int)), this,
51 SLOT(itemClicked(int)));
58 QList<Cache::LogDetails> logList;
60 Cache::instance().getLogItems(logList, LOG_MAX_ITEMS);
62 if(logList.size() == 0)
64 QLabel* info = new QLabel(tr("There are currently no logged calls"));
65 info->setAlignment(Qt::AlignCenter);
66 setCentralWidget(info);
71 for(int i = 0; i < logList.size(); i++)
73 QMap <QString, QVariant> data;
74 data["name"] = QVariant(logList.at(i).result.name);
75 data["street"] = QVariant(logList.at(i).result.street);
76 data["city"] = QVariant(logList.at(i).result.city);
77 data["number"] = QVariant(logList.at(i).result.number);
78 data["country"] = QVariant(logList.at(i).result.country);
80 list_->addWidget(createWidget(logList.at(i)), data);
85 void LogWindow::itemClicked(int index)
92 QMap <QString, QVariant> data = list_->getData(index).toMap();
93 Source::Result details;
94 details.name = data["name"].toString();
96 if(details.name.isEmpty())
101 details.street = data["street"].toString();
102 details.city = data["city"].toString();
103 details.number = data["number"].toString();
104 details.country = data["country"].toString();
106 emit logItemSelected(details);
109 QWidget* LogWindow::createWidget(Cache::LogDetails const& details)
111 QWidget* widget = new QWidget;
112 QHBoxLayout* layout = new QHBoxLayout;
118 icon = QIcon::fromTheme("general_missed");
122 icon = QIcon::fromTheme("general_received");
125 QLabel* label = new QLabel;
126 label->setPixmap(icon.pixmap(48, 48));
128 layout->addWidget(label);
130 QVBoxLayout* content = new QVBoxLayout;
134 if(details.result.name.isEmpty())
136 text = tr("%1 (no search results)").arg(details.result.number);
140 text = details.result.name;
142 if(!details.result.street.isEmpty())
144 text += ", " + details.result.street;
147 if(!details.result.city.isEmpty())
149 text += ", " + details.result.city;
153 QLabel* nameLabel = new QLabel(text);
155 QDateTime date = QDateTime::fromTime_t(details.time);
156 QLabel* dateLabel = new QLabel(date.toString(Qt::SystemLocaleShortDate));
158 font.setPointSize(11);
159 dateLabel->setFont(font);
161 content->addWidget(nameLabel);
162 content->addWidget(dateLabel);
164 layout->addLayout(content, Qt::AlignLeft);
166 widget->setLayout(layout);
171 void LogWindow::clearLog()
173 Cache::instance().clearLog();