/***************************************************************************
* Copyright (C) 2006 by S�bastien Laot *
* slaout@linux62.org *
* *
* 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. *
* *
* 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 " + i18n("This is a quick feedback system for %1.").tqarg(s_about->programName()) + " " + i18n("To help us improve it, your comments are important.") + " " + i18n("Each time you have a great or frustrating experience, "
"please click the appropriate hand below the window title-bar, "
"briefly describe what you like or dislike and click Send.") + " " + i18n("Icons description:") + ""
"
"
" "
" "
"
" + i18n("Please provide your email address.") + "
" + "" + i18n("It will only be used to contact you back if more information is needed about your comments, how to reproduce the bugs you report, send bug corrections for you to test...") + "
" + "" + i18n("The email address is optional. If you do not provide any, your comments will be sent anonymously. Just click OK in that case.") + "
" + "" + i18n("You can change or remove your email address whenever you want. For that, use the little arrow icon at the top-right corner of a window.") + "
" + "" + i18n("Your email address (keep empty to post comments anonymously):"), currentEMailAddress, &ok, TQT_TQWIDGET(kapp->activeWindow()), /*name=*/(const char*)0, &emailValidator); enable(); if (ok) setEmailAddress(email); } // FIXME: Should be moved to KAboutData? Cigogne will also need it. bool LikeBack::isDevelopmentVersion(const TQString &version) { TQString theVersion = (version.isEmpty() ? s_about->version() : version); return theVersion.tqfind("alpha", /*index=*/0, /*caseSensitive=*/false) != -1 || theVersion.tqfind("beta", /*index=*/0, /*caseSensitive=*/false) != -1 || theVersion.tqfind("rc", /*index=*/0, /*caseSensitive=*/false) != -1 || theVersion.tqfind("svn", /*index=*/0, /*caseSensitive=*/false) != -1 || theVersion.tqfind("cvs", /*index=*/0, /*caseSensitive=*/false) != -1; } void LikeBack::init(KConfig* config, KAboutData* about, Button buttons) { s_config = config; s_about = about; init(isDevelopmentVersion(), buttons); } void LikeBack::init(Button buttons) { init(isDevelopmentVersion(), buttons); } void LikeBack::init(bool isDevelopmentVersion, Button buttons) { if (s_config == 0) s_config = kapp->config(); if (s_about == 0) s_about = (KAboutData*) kapp->aboutData(); if (LikeBack::userWantToParticipate() && isDevelopmentVersion) new LikeBack(buttons); } /** * Code from KBugReport::slotConfigureEmail() in kdeui/kbugreport.cpp: */ /*void LikeBack::beginFetchingEmail() { if (m_process) return; m_process = new KProcess(); *m_process << TQString::tqfromLatin1("kcmshell") << TQString::tqfromLatin1("kcm_useraccount"); connect( m_process, TQT_SIGNAL(processExited(KProcess*)), TQT_SLOT(endFetchingEmailFrom()) ); if (!m_process->start()) { kdDebug() << "Couldn't start kcmshell.." << endl; delete m_process; m_process = 0; return; } // m_configureEmail->setEnabled(false); }*/ /** * Code from KBugReport::slotSetFrom() in kdeui/kbugreport.cpp: */ void LikeBack::endFetchingEmailFrom() { // delete m_process; // m_process = 0; // m_configureEmail->setEnabled(true); // ### KDE4: why oh why is KEmailSettings in kio? KConfig emailConf( TQString::tqfromLatin1("emaildefaults") ); // find out the default profile emailConf.setGroup(TQString::tqfromLatin1("Defaults")); TQString profile = TQString::tqfromLatin1("PROFILE_"); profile += emailConf.readEntry(TQString::tqfromLatin1("Profile"), TQString::tqfromLatin1("Default")); emailConf.setGroup(profile); TQString fromaddr = emailConf.readEntry(TQString::tqfromLatin1("EmailAddress")); if (fromaddr.isEmpty()) { struct passwd *p; p = getpwuid(getuid()); m_fetchedEmail = TQString::tqfromLatin1(p->pw_name); } else { TQString name = emailConf.readEntry(TQString::tqfromLatin1("FullName")); if (!name.isEmpty()) m_fetchedEmail = /*name + TQString::tqfromLatin1(" <") +*/ fromaddr /*+ TQString::tqfromLatin1(">")*/; } // m_from->setText( fromaddr ); } /** class LikeBackDialog: */ LikeBackDialog::LikeBackDialog(LikeBack::Button reason, TQString windowName, TQString context) : KDialog(TQT_TQWIDGET(kapp->activeWindow()), "_likeback_feedback_window_") , m_reason(reason) , m_windowName(windowName) , m_context(context) { setModal(true); TQVBoxLayout *mainLayout = new TQVBoxLayout(this); TQWidget *coloredWidget = new TQWidget(this); TQLabel *explainings = new TQLabel(this); TQHBoxLayout *explainingLayout = new TQHBoxLayout((TQWidget*)0, KDialogBase::marginHint()); explainingLayout->addWidget(explainings); mainLayout->addWidget(coloredWidget); TQColor color; TQColor lineColor; TQPixmap icon; TQString title; TQString please; switch (reason) { case LikeBack::ILike: color = TQColor("#DFFFDF"); lineColor = TQt::green; icon = kapp->iconLoader()->loadIcon("likeback_like", KIcon::Small); title = i18n("I like..."); please = i18n("Please briefly describe what you like."); break; case LikeBack::IDoNotLike: color = TQColor("#FFDFDF"); lineColor = TQt::red; icon = kapp->iconLoader()->loadIcon("likeback_dislike", KIcon::Small); title = i18n("I do not like..."); please = i18n("Please briefly describe what you do not like."); break; case LikeBack::IFoundABug: color = TQColor("#C0C0C0"); lineColor = TQt::black; icon = kapp->iconLoader()->loadIcon("bug", KIcon::Small); title = i18n("I found a bug..."); please = i18n("Please briefly describe the bug you encountered."); break; case LikeBack::Configure: case LikeBack::AllButtons: return; } TQWidget *line = new TQWidget(this); line->setPaletteBackgroundColor(lineColor); line->setFixedHeight(1); mainLayout->addWidget(line); mainLayout->addLayout(explainingLayout); TQHBoxLayout *titleLayout = new TQHBoxLayout(0); coloredWidget->setPaletteBackgroundColor(color); TQLabel *iconLabel = new TQLabel(coloredWidget); iconLabel->setPixmap(icon); TQLabel *titleLabel = new TQLabel(title, coloredWidget); TQFont font = titleLabel->font(); font.setBold(true); titleLabel->setFont(font); titleLabel->setPaletteForegroundColor(TQt::black); titleLayout->addWidget(iconLabel); titleLayout->addSpacing(4); titleLayout->addWidget(titleLabel); titleLayout->addStretch(); TQVBoxLayout *coloredWidgetLayout = new TQVBoxLayout(coloredWidget); coloredWidgetLayout->setMargin(KDialogBase::marginHint()); coloredWidgetLayout->setSpacing(KDialogBase::spacingHint()); coloredWidgetLayout->addLayout(titleLayout); TQHBoxLayout *commentLayout = new TQHBoxLayout((TQWidget*)0); commentLayout->setMargin(0); commentLayout->setSpacing(KDialogBase::spacingHint()); m_comment = new TQTextEdit(coloredWidget); TQIconSet sendIconSet = kapp->iconLoader()->loadIconSet("mail_send", KIcon::Toolbar); m_sendButton = new TQPushButton(sendIconSet, i18n("Send"), coloredWidget); m_sendButton->tqsetSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Expanding); m_sendButton->setEnabled(false); connect( m_sendButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(send()) ); connect( m_comment, TQT_SIGNAL(textChanged()), this, TQT_SLOT(commentChanged()) ); commentLayout->addWidget(m_comment); commentLayout->addWidget(m_sendButton); coloredWidgetLayout->addLayout(commentLayout); explainings->setText( "
" + please + " " + (LikeBack::customLanguageMessage().isEmpty() ? i18n("Only english language is accepted.") : LikeBack::customLanguageMessage() ) + " " + (reason == LikeBack::ILike || reason == LikeBack::IDoNotLike ? i18n("Note that to improve this application, it's important to tell us the things you like as much as the things you dislike.") + " " : "" ) + (LikeBack::allowFeatureWishes() ? "" : i18n("Do not ask for features: your wishes will be ignored.") ) + "
" ); resize(kapp->desktop()->width() / 2, kapp->desktop()->height() / 3); setCaption(kapp->makeStdCaption(i18n("Send a Comment"))); // setMinimumSize(mainLayout->tqsizeHint()); // FIXME: Doesn't work! } LikeBackDialog::~LikeBackDialog() { } TQHttp *http ; void LikeBackDialog::send() { TQString emailAddress = LikeBack::instance()->emailAddress(); TQString type = (m_reason == LikeBack::ILike ? "Like" : (m_reason == LikeBack::IDoNotLike ? "Dislike" : "Bug")); TQString data = "protocol=" + KURL::encode_string("1.0") + "&" + "type=" + KURL::encode_string(type) + "&" + "version=" + KURL::encode_string(LikeBack::about()->version()) + "&" + "locale=" + KURL::encode_string(KGlobal::locale()->language()) + "&" + "window=" + KURL::encode_string(m_windowName) + "&" + "context=" + KURL::encode_string(m_context) + "&" + "comment=" + KURL::encode_string(m_comment->text()) + "&" + "email=" + KURL::encode_string(emailAddress); //TQByteArray *data = new TQByteArray(); /*TQHttp **/http = new TQHttp(LikeBack::hostName(), LikeBack::hostPort()); // std::cout << "http://" << LikeBack::hostName() << ":" << LikeBack::hostPort() << LikeBack::remotePath() << std::endl; // std::cout << data << std::endl; connect( http, TQT_SIGNAL(requestFinished(int, bool)), this, TQT_SLOT(requestFinished(int, bool)) ); // http->post(LikeBack::remotePath(), data.utf8()); TQHttpRequestHeader header("POST", LikeBack::remotePath()); header.setValue("Host", LikeBack::hostName()); header.setValue("Content-Type", "application/x-www-form-urlencoded"); http->setHost(LikeBack::hostName()); http->request(header, data.utf8()); m_comment->setEnabled(false); } void LikeBackDialog::requestFinished(int /*id*/, bool error) { // TODO: Save to file if error (connection not present at the moment) m_comment->setEnabled(true); LikeBack::disable(); if (error) { KMessageBox::error(this, i18n("Error while trying to send the report.
Please retry later.
"), i18n("Transfer Error")); } else { KMessageBox::information(this, i18n("Your comment has been sent successfully. It will help improve the application.
Thanks for your time.
") /*+ TQString(http->readAll())*/, i18n("Comment Sent")); close(); } LikeBack::enable(); } void LikeBackDialog::commentChanged() { m_sendButton->setEnabled(!m_comment->text().isEmpty()); }