You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
3.5 KiB
125 lines
3.5 KiB
/* |
|
Copyright (c) 2013-2015 Montel Laurent <montel@kde.org> |
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
under the terms of the GNU General Public License, version 2, as |
|
published by the Free Software Foundation. |
|
|
|
This program is distributed in the hope that it will be useful, but |
|
WITHOUT ANY WARRANTY; without even the implied warranty of |
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
General Public License for more details. |
|
|
|
You should have received a copy of the GNU General Public License along |
|
with this program; if not, write to the Free Software Foundation, Inc., |
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
*/ |
|
|
|
#include "vacationscriptindicatorwidget.h" |
|
#include <QIcon> |
|
#include <KLocalizedString> |
|
|
|
#include <QHBoxLayout> |
|
|
|
using namespace KMail; |
|
|
|
ServerLabel::ServerLabel(const QString &serverName, QWidget *parent) |
|
: QLabel(parent), |
|
mServerName(serverName) |
|
{ |
|
setToolTip(serverName); |
|
setPixmap(QIcon::fromTheme(QStringLiteral("network-server")).pixmap(16, 16)); |
|
setStyleSheet(QStringLiteral("background-color: %1;").arg(QColor(Qt::yellow).name())); |
|
setContentsMargins(2, 0, 4, 0); |
|
} |
|
|
|
ServerLabel::~ServerLabel() |
|
{ |
|
|
|
} |
|
|
|
void ServerLabel::mouseReleaseEvent(QMouseEvent *event) |
|
{ |
|
Q_EMIT clicked(mServerName); |
|
QLabel::mouseReleaseEvent(event); |
|
} |
|
|
|
VacationLabel::VacationLabel(const QString &text, QWidget *parent) |
|
: QLabel(text, parent) |
|
{ |
|
// changing the palette doesn't work, seems to be overwriten by the |
|
// statusbar again, stylesheets seems to work though |
|
setStyleSheet(QStringLiteral("background-color: %1; color: %2;").arg(QColor(Qt::yellow).name(), QColor(Qt::black).name())); |
|
setContentsMargins(4, 0, 2, 0); |
|
setCursor(QCursor(Qt::PointingHandCursor)); |
|
} |
|
|
|
VacationLabel::~VacationLabel() |
|
{ |
|
|
|
} |
|
|
|
void VacationLabel::mouseReleaseEvent(QMouseEvent *event) |
|
{ |
|
Q_EMIT clicked(); |
|
QLabel::mouseReleaseEvent(event); |
|
} |
|
|
|
VacationScriptIndicatorWidget::VacationScriptIndicatorWidget(QWidget *parent) |
|
: QWidget(parent), |
|
mBoxLayout(Q_NULLPTR), |
|
mInfo(Q_NULLPTR) |
|
{ |
|
} |
|
|
|
VacationScriptIndicatorWidget::~VacationScriptIndicatorWidget() |
|
{ |
|
|
|
} |
|
|
|
void VacationScriptIndicatorWidget::setVacationScriptActive(bool active, const QString &serverName) |
|
{ |
|
if (active) { |
|
if (!mServerActive.contains(serverName)) { |
|
mServerActive.append(serverName); |
|
updateIndicator(); |
|
} |
|
} else { |
|
if (mServerActive.contains(serverName)) { |
|
mServerActive.removeAll(serverName); |
|
updateIndicator(); |
|
} |
|
} |
|
} |
|
|
|
void VacationScriptIndicatorWidget::createIndicator() |
|
{ |
|
delete mBoxLayout; |
|
mBoxLayout = new QHBoxLayout; |
|
mBoxLayout->setMargin(0); |
|
mBoxLayout->setSpacing(0); |
|
mInfo = new VacationLabel(i18np("Out of office reply active on server", "Out of office reply active on servers", mServerActive.count())); |
|
connect(mInfo, SIGNAL(clicked()), this, SIGNAL(clicked())); |
|
mBoxLayout->addWidget(mInfo); |
|
Q_FOREACH (const QString &server, mServerActive) { |
|
ServerLabel *lab = new ServerLabel(server); |
|
connect(lab, &ServerLabel::clicked, this, &VacationScriptIndicatorWidget::clicked); |
|
mBoxLayout->addWidget(lab); |
|
} |
|
setLayout(mBoxLayout); |
|
} |
|
|
|
void VacationScriptIndicatorWidget::updateIndicator() |
|
{ |
|
if (mServerActive.isEmpty()) { |
|
hide(); |
|
} else { |
|
createIndicator(); |
|
show(); |
|
} |
|
} |
|
|
|
bool VacationScriptIndicatorWidget::hasVacationScriptActive() const |
|
{ |
|
return !mServerActive.isEmpty(); |
|
}
|
|
|