File indexing completed on 2023-11-26 04:55:36
0001 /* 0002 Extended KMessageWidget for link-local xmpp account autocreation 0003 Copyright (C) 2011 Martin Klapetek <martin.klapetek@gmail.com> 0004 Copyright (C) 2012 Daniele E. Domenichelli <daniele.domenichelli@gmail.com> 0005 0006 This library is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU Lesser General Public 0008 License as published by the Free Software Foundation; either 0009 version 2.1 of the License, or (at your option) any later version. 0010 0011 This library is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 Lesser General Public License for more details. 0015 0016 You should have received a copy of the GNU Lesser General Public 0017 License along with this library; if not, write to the Free Software 0018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0019 */ 0020 0021 0022 #include "salut-message-widget.h" 0023 0024 #include <KTp/circular-countdown.h> 0025 0026 #include <KLocalizedString> 0027 #include <KIcon> 0028 #include <KAction> 0029 #include <KDebug> 0030 0031 #include <QtGui/QLayout> 0032 #include <QtGui/QWidgetAction> 0033 #include <QtGui/QVBoxLayout> 0034 0035 SalutMessageWidget::SalutMessageWidget(QWidget *parent) 0036 : KMessageWidget(parent) 0037 { 0038 setMessageType(KMessageWidget::Information); 0039 setWordWrap(true); 0040 QSize sz = size(); 0041 sz.setWidth(parent->size().width()); 0042 resize(sz); 0043 0044 setCloseButtonVisible(false); 0045 0046 KTp::CircularCountdown *circCountdown = new KTp::CircularCountdown(8000, this); 0047 0048 connect(circCountdown, SIGNAL(timeout()), this, SIGNAL(timeout())); 0049 0050 KAction *configAction = new KAction(KIcon(QLatin1String("configure")), i18n("Configure manually..."), this); 0051 connect(configAction, SIGNAL(triggered(bool)), this, SIGNAL(configPressed())); 0052 addAction(configAction); 0053 0054 KAction *cancelAction = new KAction(KIcon(QLatin1String("dialog-cancel")), i18n("Cancel"), this); 0055 connect(cancelAction, SIGNAL(triggered(bool)), this, SIGNAL(cancelPressed())); 0056 addAction(cancelAction); 0057 0058 //whatever will user choose, stop the countdown 0059 connect(this, SIGNAL(cancelPressed()), circCountdown, SLOT(stop())); 0060 connect(this, SIGNAL(configPressed()), circCountdown, SLOT(stop())); 0061 0062 //6px padding for the CircularCountdown 0063 int padding = 6; 0064 0065 //this takes the CircularCountdown and moves it to the top right corner of this message widget 0066 //16 is the width of CC, but somehow circCountdown->width() doesn't work right, so it's harcoded 0067 circCountdown->move(this->width() - (16 + padding), padding); 0068 circCountdown->start(); 0069 } 0070 0071 SalutMessageWidget::~SalutMessageWidget() 0072 { 0073 } 0074 0075 ///these params always comes from KUser with first & last name split manually by the last space 0076 void SalutMessageWidget::setParams(const QString& firstname, const QString& lastname, const QString& nickname) 0077 { 0078 QString displayName; 0079 0080 if (!firstname.isEmpty()) { 0081 displayName = firstname; 0082 } 0083 0084 if (!lastname.isEmpty()) { 0085 if (!displayName.isEmpty()) { 0086 displayName.append(QString::fromLatin1(" %1").arg(lastname)); 0087 } else { 0088 displayName = lastname; 0089 } 0090 } 0091 0092 if (!nickname.isEmpty()) { 0093 if (!displayName.isEmpty()) { 0094 displayName.append(QString::fromLatin1(" (%1)").arg(nickname)); 0095 } else { 0096 displayName = nickname; 0097 } 0098 } 0099 if (displayName.isEmpty()) { 0100 //FIXME: let the user know that he reached a very strange situation 0101 kWarning() << "All fields are empty"; 0102 } 0103 0104 setText(i18n("You will appear as \"%1\" on your local network.", 0105 displayName)); 0106 }