Commit c352f2df authored by Kelvie Wong's avatar Kelvie Wong
Browse files

Added the new likeback dialog from Valerio Pilo.

Valerio (valerio@kmess.org) sent me these changes.  The dialog is now a lot simpler
and more compact.
parent 14fd1005
......@@ -35,6 +35,8 @@ set(basketcommon_LIB_SRCS
regiongrabber.cpp
kgpgme.cpp
likeback.cpp
likebackbar.cpp
likebackdialog.cpp
crashhandler.cpp
password.cpp
colorpicker.cpp
......@@ -45,7 +47,7 @@ set(basketcommon_LIB_SRCS
basketstatusbar.cpp
backup.cpp)
kde4_add_ui_files(basketcommon_LIB_SRCS passwordlayout.ui)
kde4_add_ui_files(basketcommon_LIB_SRCS passwordlayout.ui likebackbar.ui likebackdialog.ui)
QT4_ADD_DBUS_ADAPTOR(basketcommon_LIB_SRCS org.basket.BNPView.xml bnpview.h BNPView)
......
This diff is collapsed.
......@@ -21,7 +21,7 @@
#ifndef LIKEBACK_H
#define LIKEBACK_H
#include <qobject.h>
#include <QObject>
class KConfig;
class KAboutData;
......@@ -29,8 +29,6 @@ class KAction;
class KActionCollection;
class LikeBackPrivate;
class LikeBackBar;
class LikeBackDialog;
/**
* @short System to Get Quick Feedback from Beta-Testers
......
......@@ -21,85 +21,64 @@
#ifndef LIKEBACK_PRIVATE_H
#define LIKEBACK_PRIVATE_H
#include <KDialog>
#include <qtimer.h>
#include <QTimer>
#include "likeback.h"
class QToolButton;
class Q3TextEdit;
class QCheckBox;
class Q3ButtonGroup;
class QButtonGroup;
class Kaction;
class LikeBackPrivate
{
public:
LikeBackPrivate();
~LikeBackPrivate();
LikeBackBar *bar;
KConfig *config;
const KAboutData *aboutData;
LikeBack::Button buttons;
QString hostName;
QString remotePath;
quint16 hostPort;
QStringList acceptedLocales;
QString acceptedLanguagesMessage;
LikeBack::WindowListing windowListing;
bool showBarByDefault;
bool showBar;
int disabledCount;
QString fetchedEmail;
KAction *action;
LikeBackPrivate();
~LikeBackPrivate();
LikeBackBar *bar;
KConfig *config;
const KAboutData *aboutData;
LikeBack::Button buttons;
QString hostName;
QString remotePath;
quint16 hostPort;
QStringList acceptedLocales;
QString acceptedLanguagesMessage;
LikeBack::WindowListing windowListing;
bool showBarByDefault;
bool showBar;
int disabledCount;
QString fetchedEmail;
KAction *action;
};
class LikeBackBar : public QWidget
LikeBackPrivate::LikeBackPrivate()
: bar(0)
, config(0)
, aboutData(0)
, buttons(LikeBack::DefaultButtons)
, hostName()
, remotePath()
, hostPort(80)
, acceptedLocales()
, acceptedLanguagesMessage()
, windowListing(LikeBack::NoListing)
, showBar(false)
, disabledCount(0)
, fetchedEmail()
, action(0)
{
Q_OBJECT
public:
LikeBackBar(LikeBack *likeBack);
~LikeBackBar();
public slots:
void startTimer();
void stopTimer();
private slots:
void autoMove();
void clickedLike();
void clickedDislike();
void clickedBug();
void clickedFeature();
private:
LikeBack *m_likeBack;
QTimer m_timer;
QToolButton *m_likeButton;
QToolButton *m_dislikeButton;
QToolButton *m_bugButton;
QToolButton *m_featureButton;
};
}
class LikeBackDialog : public KDialog
LikeBackPrivate::~LikeBackPrivate()
{
Q_OBJECT
public:
LikeBackDialog(LikeBack::Button reason, const QString &initialComment, const QString &windowPath, const QString &context, LikeBack *likeBack);
~LikeBackDialog();
private:
LikeBack *m_likeBack;
QString m_windowPath;
QString m_context;
Q3ButtonGroup *m_group;
Q3TextEdit *m_comment;
QCheckBox *m_showButtons;
QString introductionText();
private slots:
void polish();
void slotDefault();
void slotOk();
void changeButtonBarVisible();
void commentChanged();
void send();
void requestFinished(int id, bool error);
};
delete bar;
delete action;
config = 0;
aboutData = 0;
}
#endif // LIKEBACK_PRIVATE_H
/***************************************************************************
(filename).cpp - description
-------------------
begin : (Weekday) (Month) (day) 2008
copyright : (C) 2008 by (yourname)
email : (e-mail address)
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <KApplication>
#include <KDebug>
#include "likebackbar.h"
LikeBackBar::LikeBackBar( LikeBack *likeBack )
: QWidget( 0, Qt::Tool | Qt::X11BypassWindowManagerHint )
/* Qt::WX11BypassWM | Qt::WStyle_NoBorder | Qt::WNoAutoErase | Qt::WStyle_StaysOnTop | Qt::WStyle_NoBorder | Qt::WGroupLeader */
, Ui::LikeBackBar()
, m_likeBack( likeBack )
{
// Set up the user interface
setupUi( this );
// Set the button icons
m_likeButton ->setIcon( KIcon( "likeback_like" ) );
m_dislikeButton->setIcon( KIcon( "likeback_dislike" ) );
m_bugButton ->setIcon( KIcon( "likeback_bug" ) );
m_featureButton->setIcon( KIcon( "likeback_feature" ) );
connect( &m_timer, SIGNAL(timeout()), this, SLOT(autoMove()) );
LikeBack::Button buttons = likeBack->buttons();
m_likeButton ->setShown( buttons & LikeBack::Like );
m_dislikeButton->setShown( buttons & LikeBack::Dislike );
m_bugButton ->setShown( buttons & LikeBack::Bug );
m_featureButton->setShown( buttons & LikeBack::Feature );
}
LikeBackBar::~LikeBackBar()
{
}
void LikeBackBar::startTimer()
{
m_timer.start(10);
}
void LikeBackBar::stopTimer()
{
m_timer.stop();
}
void LikeBackBar::autoMove()
{
static QWidget *lastWindow = 0;
QWidget *window = kapp->activeWindow();
// When a Kicker applet has the focus, like the Commandline QLineEdit,
// the systemtray icon indicates to be the current window and the LikeBack is shown next to the system tray icon.
// It's obviously bad ;-) :
bool shouldShow = (m_likeBack->userWantsToShowBar() && m_likeBack->enabledBar() && window && !window->inherits("KSystemTray"));
if (shouldShow) {
//move(window->x() + window->width() - 100 - width(), window->y());
//move(window->x() + window->width() - 100 - width(), window->mapToGlobal(QPoint(0, 0)).y() - height());
move(window->mapToGlobal(QPoint(0, 0)).x() + window->width() - width(), window->mapToGlobal(QPoint(0, 0)).y() + 1);
if (window != lastWindow && m_likeBack->windowNamesListing() != LikeBack::NoListing) {
if( window->objectName() == "unnamed" || window->objectName() == "unnamed" )
{
kDebug() << "===== LikeBack ===== UNNAMED ACTIVE WINDOW OF TYPE " << window->metaObject()->className() << " ======" << LikeBack::activeWindowPath();
} else if (m_likeBack->windowNamesListing() == LikeBack::AllWindows) {
kDebug() << "LikeBack: Active Window: " << LikeBack::activeWindowPath();
}
}
lastWindow = window;
}
// Show or hide the bar accordingly:
if (shouldShow && !isVisible()) {
show();
} else if (!shouldShow && isVisible()) {
hide();
}
}
void LikeBackBar::likeClicked()
{
kDebug() << "LIKE";
m_likeBack->execCommentDialog( LikeBack::Like );
}
void LikeBackBar::dislikeClicked()
{
kDebug() << "DISLIKE";
m_likeBack->execCommentDialog( LikeBack::Dislike );
}
void LikeBackBar::bugClicked()
{
kDebug() << "BUG";
m_likeBack->execCommentDialog( LikeBack::Bug );
}
void LikeBackBar::featureClicked()
{
kDebug() << "FEATURE";
m_likeBack->execCommentDialog( LikeBack::Feature );
}
#ifndef LIKEBACKBAR_H
#define LIKEBACKBAR_H
#include <QTimer>
#include <QWidget>
#include "likeback.h"
#include "ui_likebackbar.h"
class LikeBackBar : public QWidget, private Ui::LikeBackBar
{
Q_OBJECT
public:
LikeBackBar( LikeBack *likeBack );
~LikeBackBar();
public slots:
void startTimer();
void stopTimer();
private slots:
void autoMove();
void likeClicked();
void dislikeClicked();
void bugClicked();
void featureClicked();
private:
LikeBack *m_likeBack;
QTimer m_timer;
};
#endif
<ui version="4.0" >
<class>LikeBackBar</class>
<widget class="QWidget" name="LikeBackBar" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>96</width>
<height>24</height>
</rect>
</property>
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle" >
<string/>
</property>
<property name="autoFillBackground" >
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout" >
<property name="spacing" >
<number>0</number>
</property>
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="m_likeButton" >
<property name="text" >
<string/>
</property>
<property name="autoRaise" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="m_dislikeButton" >
<property name="text" >
<string/>
</property>
<property name="autoRaise" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="m_bugButton" >
<property name="text" >
<string/>
</property>
<property name="autoRaise" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="m_featureButton" >
<property name="text" >
<string/>
</property>
<property name="autoRaise" >
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>m_likeButton</sender>
<signal>clicked()</signal>
<receiver>LikeBackBar</receiver>
<slot>likeClicked()</slot>
<hints>
<hint type="sourcelabel" >
<x>23</x>
<y>23</y>
</hint>
<hint type="destinationlabel" >
<x>72</x>
<y>0</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_dislikeButton</sender>
<signal>clicked()</signal>
<receiver>LikeBackBar</receiver>
<slot>dislikeClicked()</slot>
<hints>
<hint type="sourcelabel" >
<x>45</x>
<y>17</y>
</hint>
<hint type="destinationlabel" >
<x>95</x>
<y>0</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_bugButton</sender>
<signal>clicked()</signal>
<receiver>LikeBackBar</receiver>
<slot>bugClicked()</slot>
<hints>
<hint type="sourcelabel" >
<x>67</x>
<y>20</y>
</hint>
<hint type="destinationlabel" >
<x>95</x>
<y>1</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_featureButton</sender>
<signal>clicked()</signal>
<receiver>LikeBackBar</receiver>
<slot>featureClicked()</slot>
<hints>
<hint type="sourcelabel" >
<x>93</x>
<y>13</y>
</hint>
<hint type="destinationlabel" >
<x>95</x>
<y>13</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>likeClicked()</slot>
<slot>dislikeClicked()</slot>
<slot>bugClicked()</slot>
<slot>featureClicked()</slot>
</slots>
</ui>
#include <QHttp>
#include <QHttpRequestHeader>
#include <KAboutData>
#include <KApplication>
#include <KDebug>
#include <KMessageBox>
#include <KPushButton>
#include "likebackdialog.h"
LikeBackDialog::LikeBackDialog(LikeBack::Button reason, const QString &initialComment, const QString &windowPath, const QString &context, LikeBack *likeBack)
: KDialog(kapp->activeWindow())
, Ui::LikeBackDialog()
, m_likeBack(likeBack)
, m_windowPath(windowPath)
, m_context(context)
{
// KDialog Options
setCaption( i18n( "Send a Comment to Developers" ) );
setButtons( Ok | Cancel );
setDefaultButton( Ok );
setObjectName( "_likeback_feedback_window_" );
showButtonSeparator( true );
// Set up the user interface
QWidget *mainWidget = new QWidget( this );
setupUi( mainWidget );
setMainWidget( mainWidget );
// The introduction message is long and will require a new minimum dialog size
m_informationLabel->setText( introductionText() );
setMinimumSize( minimumSizeHint() );
m_typeGroup_ = new QButtonGroup( this );
m_typeGroup_->addButton( likeRadio_, LikeBack::Like );
m_typeGroup_->addButton( dislikeRadio_, LikeBack::Dislike );
m_typeGroup_->addButton( bugRadio_, LikeBack::Bug );
m_typeGroup_->addButton( featureRadio_, LikeBack::Feature );
LikeBack::Button buttons = m_likeBack->buttons();
// If no specific "reason" is provided, choose the first one:
if( reason == LikeBack::AllButtons )
{
int firstButton = 0;
if( (buttons & LikeBack::Like) ) firstButton = LikeBack::Like;
if( firstButton == 0 && (buttons & LikeBack::Dislike) ) firstButton = LikeBack::Dislike;
if( firstButton == 0 && (buttons & LikeBack::Bug) ) firstButton = LikeBack::Bug;
if( firstButton == 0 && (buttons & LikeBack::Feature) ) firstButton = LikeBack::Feature;
reason = (LikeBack::Button) firstButton;
switch( firstButton )
{
case LikeBack::Like: likeRadio_ ->setChecked( true ); break;
case LikeBack::Dislike: dislikeRadio_->setChecked( true ); break;
case LikeBack::Bug: bugRadio_ ->setChecked( true ); break;
case LikeBack::Feature: featureRadio_->setChecked( true ); break;
}
}
// If no window path is provided, get the current active window path:
if( m_windowPath.isEmpty() )
{
m_windowPath = LikeBack::activeWindowPath();
}
likeRadio_ ->setVisible( buttons & LikeBack::Like );
dislikeRadio_->setVisible( buttons & LikeBack::Dislike );
bugRadio_ ->setVisible( buttons & LikeBack::Bug );
featureRadio_->setVisible( buttons & LikeBack::Feature );
m_comment->setPlainText( initialComment );
m_comment->setFocus();
}
LikeBackDialog::~LikeBackDialog()
{
}
QString LikeBackDialog::introductionText()
{
QString text = "<p>" + i18n("Please provide a brief description of your opinion of %1.", m_likeBack->aboutData()->programName()) + " ";
QString languagesMessage = "";
if (!m_likeBack->acceptedLocales().isEmpty() && !m_likeBack->acceptedLanguagesMessage().isEmpty()) {
languagesMessage = m_likeBack->acceptedLanguagesMessage();
QStringList locales = m_likeBack->acceptedLocales();
for (QStringList::Iterator it = locales.begin(); it != locales.end(); ++it) {
QString locale = *it;
if (KGlobal::locale()->language().startsWith(locale))
languagesMessage = "";
}
} else {
if (!KGlobal::locale()->language().startsWith("en"))
languagesMessage = i18n("Please write in English.");
}
if (!languagesMessage.isEmpty())
// TODO: Replace the URL with a localized one:
text += languagesMessage + " " +
i18n("You may be able to use an <a href=\"%1\">online translation tool</a>."
, "http://www.google.com/language_tools?hl=" + KGlobal::locale()->language()) + " ";
// If both "I Like" and "I Dislike" buttons are shown and one is clicked:
if ((m_likeBack->buttons() & LikeBack::Like) && (m_likeBack->buttons() & LikeBack::Dislike))
text += i18n("To make the comments you send more useful in improving this application, try to send the same amount of positive and negative comments.") + " ";
if (!(m_likeBack->buttons() & LikeBack::Feature))
text += i18n("Do <b>not</b> ask for new features: your requests will be ignored.");
return text;
}
void LikeBackDialog::slotDefault()
{
m_likeBack->askEmailAddress();
}
void LikeBackDialog::slotOk()
{
send();
}
void LikeBackDialog::commentChanged()
{
KPushButton *sendButton = button(Ok);
sendButton->setEnabled( ! m_comment->document()->isEmpty() );
}
void LikeBackDialog::send()
{
QString type;
QString emailAddress = m_likeBack->emailAddress();
switch( m_typeGroup_->checkedId() )
{
case LikeBack::Like: type = "Like"; break;
case LikeBack::Dislike: type = "Dislike"; break;
case LikeBack::Bug: type = "Bug"; break;
case LikeBack::Feature: type = "Feature"; break;
}
QString data = "protocol=" + QUrl::toPercentEncoding( "1.0" ) + '&' +
"type=" + QUrl::toPercentEncoding( type ) + '&' +
"version=" + QUrl::toPercentEncoding( m_likeBack->aboutData()->version() ) + '&' +
"locale=" + QUrl::toPercentEncoding( KGlobal::locale()->language() ) + '&' +
"window=" + QUrl::toPercentEncoding( m_windowPath ) + '&' +
"context=" + QUrl::toPercentEncoding( m_context ) + '&' +
"comment=" + QUrl::toPercentEncoding( m_comment->toPlainText() ) + '&' +
"email=" + QUrl::toPercentEncoding( emailAddress );