Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 6e2ba928 authored by Laurent Montel's avatar Laurent Montel 😁

improve widget

parent 8d457693
......@@ -8,3 +8,8 @@ set( pimcommon_gravatar_SRCS gravatarresolvurljobtest.cpp )
kde4_add_unit_test( pimcommon_gravatartest ${pimcommon_gravatar_SRCS})
target_link_libraries( pimcommon_gravatartest ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS} pimcommon)
set( pimcommon_gravatardownloadpixmapwidget_SRCS gravatardownloadpixmapwidgettest.cpp ../widgets/gravatardownloadpixmapwidget.cpp)
kde4_add_unit_test( pimcommon_gravatardownloadpixmapwidget ${pimcommon_gravatardownloadpixmapwidget_SRCS})
target_link_libraries( pimcommon_gravatardownloadpixmapwidget ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS} pimcommon)
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
based on code from Sune Vuorela <sune@vuorela.dk> (Rawatar source code)
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 "gravatardownloadpixmapwidgettest.h"
#include "../widgets/gravatardownloadpixmapwidget.h"
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <qtest_kde.h>
GravatarDownloadPixmapWidgetTest::GravatarDownloadPixmapWidgetTest(QObject *parent)
: QObject(parent)
{
}
GravatarDownloadPixmapWidgetTest::~GravatarDownloadPixmapWidgetTest()
{
}
void GravatarDownloadPixmapWidgetTest::shouldHaveDefaultValue()
{
PimCommon::GravatarDownloadPixmapWidget w;
QLabel *lab = qFindChild<QLabel *>(&w, QLatin1String("labemail"));
QVERIFY(lab);
QLineEdit *lineEdit = qFindChild<QLineEdit *>(&w, QLatin1String("email"));
QVERIFY(lineEdit);
QPushButton *getPixmapButton = qFindChild<QPushButton *>(&w, QLatin1String("searchbutton"));
QVERIFY(getPixmapButton);
QVERIFY(!getPixmapButton->isEnabled());
}
void GravatarDownloadPixmapWidgetTest::shouldChangeButtonEnableState()
{
PimCommon::GravatarDownloadPixmapWidget w;
QLineEdit *lineEdit = qFindChild<QLineEdit *>(&w, QLatin1String("email"));
QPushButton *getPixmapButton = qFindChild<QPushButton *>(&w, QLatin1String("searchbutton"));
QVERIFY(!getPixmapButton->isEnabled());
lineEdit->setText(QLatin1String("foo"));
QVERIFY(getPixmapButton->isEnabled());
lineEdit->setText(QLatin1String(" "));
QVERIFY(!getPixmapButton->isEnabled());
}
QTEST_KDEMAIN(GravatarDownloadPixmapWidgetTest, GUI)
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
based on code from Sune Vuorela <sune@vuorela.dk> (Rawatar source code)
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
*/
#ifndef GRAVATARDOWNLOADPIXMAPWIDGETTEST_H
#define GRAVATARDOWNLOADPIXMAPWIDGETTEST_H
#include <QObject>
class GravatarDownloadPixmapWidgetTest : public QObject
{
Q_OBJECT
public:
explicit GravatarDownloadPixmapWidgetTest(QObject *parent = 0);
~GravatarDownloadPixmapWidgetTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldChangeButtonEnableState();
};
#endif // GRAVATARDOWNLOADPIXMAPWIDGETTEST_H
......@@ -81,6 +81,7 @@ void GravatarResolvUrlJob::slotFinishLoadPixmap(QNetworkReply *reply)
mHasGravatar = true;
}
reply->deleteLater();
Q_EMIT finished(this);
}
void GravatarResolvUrlJob::slotError(QNetworkReply::NetworkError error)
......
......@@ -55,7 +55,7 @@ public:
void setUseDefaultPixmap(bool useDefaultPixmap);
Q_SIGNALS:
void urlResolved(const KUrl &url);
void finished(PimCommon::GravatarResolvUrlJob *);
private Q_SLOTS:
void slotFinishLoadPixmap(QNetworkReply *reply);
......
......@@ -18,12 +18,35 @@
*/
#include "gravatardownloadpixmapwidget.h"
#include "gravatar/gravatarresolvurljob.h"
#include <QLabel>
#include <KLocalizedString>
#include <QVBoxLayout>
#include <QLineEdit>
#include <QPushButton>
#include <QDebug>
using namespace PimCommon;
GravatarDownloadPixmapWidget::GravatarDownloadPixmapWidget(QWidget *parent)
: QWidget(parent)
{
QVBoxLayout *mainLayout = new QVBoxLayout;
setLayout(mainLayout);
QHBoxLayout *hbox = new QHBoxLayout;
mainLayout->addLayout(hbox);
QLabel *lab = new QLabel(QLatin1String("Email:"));
lab->setObjectName(QLatin1String("labemail"));
hbox->addWidget(lab);
mLineEdit = new QLineEdit;
mLineEdit->setObjectName(QLatin1String("email"));
connect(mLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotTextChanged(QString)));
hbox->addWidget(mLineEdit);
mGetPixmapButton = new QPushButton(QLatin1String("searchbutton"));
mGetPixmapButton->setObjectName(QLatin1String("searchbutton"));
connect(mGetPixmapButton, SIGNAL(clicked(bool)), this, SLOT(slotSearchButton()));
hbox->addWidget(mGetPixmapButton);
mGetPixmapButton->setEnabled(false);
}
GravatarDownloadPixmapWidget::~GravatarDownloadPixmapWidget()
......@@ -31,3 +54,25 @@ GravatarDownloadPixmapWidget::~GravatarDownloadPixmapWidget()
}
void GravatarDownloadPixmapWidget::slotResolvUrlFinish(PimCommon::GravatarResolvUrlJob *job)
{
if (job) {
qDebug() << job->hasGravatar();
}
//TODO
}
void GravatarDownloadPixmapWidget::slotSearchButton()
{
PimCommon::GravatarResolvUrlJob *job = new PimCommon::GravatarResolvUrlJob(this);
job->setEmail(mLineEdit->text());
if (job->canStart()) {
connect(job, SIGNAL(finished()), this, SLOT(slotResolvUrlFinish()));
job->start();
}
}
void GravatarDownloadPixmapWidget::slotTextChanged(const QString &text)
{
mGetPixmapButton->setEnabled(!text.trimmed().isEmpty());
}
......@@ -22,13 +22,27 @@
#include <QWidget>
#include "pimcommon_export.h"
class QLabel;
class QLineEdit;
class QPushButton;
namespace PimCommon {
class GravatarResolvUrlJob;
class PIMCOMMON_EXPORT GravatarDownloadPixmapWidget : public QWidget
{
Q_OBJECT
public:
explicit GravatarDownloadPixmapWidget(QWidget *parent = 0);
~GravatarDownloadPixmapWidget();
private Q_SLOTS:
void slotSearchButton();
void slotTextChanged(const QString &text);
void slotResolvUrlFinish(PimCommon::GravatarResolvUrlJob *job);
private:
QLabel *mResultLabel;
QLineEdit *mLineEdit;
QPushButton *mGetPixmapButton;
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment