• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdenetwork
  • Sitemap
  • Contact Us
 

krfb

manageinvitationsdialog.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2007 Alessandro Praduroux <pradu@pradu.it>
00003 
00004    This program is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 */
00009 #include "manageinvitationsdialog.h"
00010 #include "manageinvitationsdialog.moc"
00011 
00012 #include "personalinvitedialog.h"
00013 #include "invitationmanager.h"
00014 #include "invitation.h"
00015 #include "krfbconfig.h"
00016 #include "krfbserver.h"
00017 
00018 #include <QWidget>
00019 #include <QToolTip>
00020 #include <QCursor>
00021 #include <QDateTime>
00022 #include <QNetworkInterface>
00023 
00024 #include <KStandardGuiItem>
00025 #include <KIconLoader>
00026 #include <KLocale>
00027 #include <KGlobal>
00028 #include <KConfigDialog>
00029 #include <KMessageBox>
00030 #include <KToolInvocation>
00031 
00032 // settings dialog
00033 #include "ui_configtcp.h"
00034 #include "ui_configsecurity.h"
00035 
00036 class TCP: public QWidget, public Ui::TCP {
00037     public:
00038         TCP(QWidget *parent=0) :QWidget(parent)
00039         {
00040             setupUi(this);
00041         }
00042 };
00043 
00044 class Security: public QWidget, public Ui::Security {
00045     public:
00046         Security(QWidget *parent=0) :QWidget(parent)
00047         {
00048             setupUi(this);
00049         }
00050 };
00051 
00052 
00053 ManageInvitationsDialog::ManageInvitationsDialog(QWidget *parent)
00054  : KDialog(parent)
00055 {
00056     setCaption(i18n("Invitation"));
00057     setButtons(User1|Close|Help);
00058     setHelp(QString(), "krfb");
00059     setDefaultButton(NoDefault);
00060 
00061     setMinimumSize(500, 330);
00062 
00063     setupUi(mainWidget());
00064     pixmapLabel->setPixmap(KIcon("krfb").pixmap(128));
00065 
00066     setButtonGuiItem( User1, KStandardGuiItem::configure() );
00067 
00068     connect( helpLabel, SIGNAL( linkActivated ( QString ) ),
00069              SLOT( showWhatsthis() ));
00070     connect( newPersonalInvitationButton, SIGNAL( clicked() ),
00071              SLOT( inviteManually() ));
00072     connect( newEmailInvitationButton, SIGNAL( clicked() ),
00073              SLOT( inviteByMail() ));
00074     connect( InvitationManager::self(), SIGNAL( invitationNumChanged( int )),
00075              SLOT( reloadInvitations() ));
00076     connect( this, SIGNAL(user1Clicked()),SLOT(showConfiguration()));
00077     connect( deleteAllButton, SIGNAL( clicked() ),
00078              SLOT( deleteAll() ));
00079     connect( deleteOneButton, SIGNAL( clicked() ),
00080              SLOT( deleteCurrent() ));
00081     connect( invitationWidget, SIGNAL(itemSelectionChanged ()),
00082              SLOT( selectionChanged() ));
00083 
00084     reloadInvitations();
00085 }
00086 
00087 ManageInvitationsDialog::~ManageInvitationsDialog()
00088 {
00089 }
00090 
00091 void ManageInvitationsDialog::showWhatsthis()
00092 {
00093     QToolTip::showText(QCursor::pos(),
00094         i18n("An invitation creates a one-time password that allows the receiver to connect to your desktop.\n"
00095             "It is valid for only one successful connection and will expire after an hour if it has not been used. \n"
00096             "When somebody connects to your computer a dialog will appear and ask you for permission.\n"
00097             "The connection will not be established before you accept it. In this dialog you can also\nrestrict "
00098             "the other person to view your desktop only, without the ability to move your\nmouse pointer or press "
00099             "keys.\nIf you want to create a permanent password for Desktop Sharing, allow 'Uninvited Connections' \n"
00100             "in the configuration."));
00101 
00102 }
00103 
00104 void ManageInvitationsDialog::inviteManually()
00105 {
00106     Invitation inv = InvitationManager::self()->addInvitation();
00107     PersonalInviteDialog *pid = new PersonalInviteDialog(this);
00108     pid->setPassword(inv.password());
00109     pid->setExpiration(inv.expirationTime());
00110     pid->show();
00111 }
00112 
00113 void ManageInvitationsDialog::inviteByMail()
00114 {
00115     int r = KMessageBox::warningContinueCancel(this,
00116             i18n("When sending an invitation by email, note that everybody who reads this email "
00117                 "will be able to connect to your computer for one hour, or until the first "
00118                 "successful connection took place, whichever comes first. \n"
00119                 "You should either encrypt the email or at least send it only in a "
00120                 "secure network, but not over the Internet."),
00121             i18n("Send Invitation via Email"),
00122             KStandardGuiItem::cont(),
00123             KStandardGuiItem::cancel(),
00124             "showEmailInvitationWarning");
00125     if (r == KMessageBox::Cancel)
00126         return;
00127 
00128     QList<QNetworkInterface> ifl = QNetworkInterface::allInterfaces();
00129     QString host;
00130     int port = KrfbConfig::port();
00131     foreach (const QNetworkInterface &nif, ifl) {
00132         if (nif.flags() & QNetworkInterface::IsLoopBack) continue;
00133         if (nif.flags() & QNetworkInterface::IsRunning) {
00134             host = nif.addressEntries()[0].ip().toString();
00135         }
00136     }
00137 
00138     Invitation inv = InvitationManager::self()->addInvitation();
00139     KUrl invUrl(QString("vnc://invitation:%1@%2:%3").arg(inv.password()).arg(host).arg(port));
00140     KToolInvocation::invokeMailer(QString(), QString(), QString(),
00141             i18n("Desktop Sharing (VNC) invitation"),
00142             ki18n("You have been invited to a VNC session. If you have the KDE Remote "
00143                   "Desktop Connection installed, just click on the link below.\n\n"
00144                   "%1\n\n"
00145                   "Otherwise you can use any VNC client with the following parameters:\n\n"
00146                   "Host: %2:%3\n"
00147                   "Password: %4\n\n"
00148                   "For security reasons this invitation will expire at %5.")
00149             .subs(invUrl.url())
00150             .subs(host)
00151             .subs(QString::number(port))
00152             .subs(inv.password())
00153             .subs(KGlobal::locale()->formatDateTime(inv.expirationTime()))
00154             .toString());
00155 
00156 }
00157 
00158 void ManageInvitationsDialog::reloadInvitations()
00159 {
00160     invitationWidget->clear();
00161     KLocale *loc = KGlobal::locale();
00162     foreach(const Invitation &inv, InvitationManager::self()->invitations()) {
00163         QStringList strs;
00164         strs <<  loc->formatDateTime(inv.creationTime()) << loc->formatDateTime(inv.expirationTime());
00165         QTreeWidgetItem *it = new QTreeWidgetItem(strs);
00166         invitationWidget->addTopLevelItem(it);
00167         it->setData(0,Qt::UserRole+1, inv.creationTime());
00168     }
00169     invitationWidget->resizeColumnToContents(0);
00170     deleteAllButton->setEnabled(InvitationManager::self()->activeInvitations() > 0);
00171 }
00172 
00173 void ManageInvitationsDialog::showConfiguration()
00174 {
00175     if(KConfigDialog::showDialog("settings"))
00176         return;
00177 
00178     KConfigDialog *dialog = new KConfigDialog(this, "settings", KrfbConfig::self());
00179     dialog->addPage(new TCP, i18n("Network"), "network-workgroup");
00180     dialog->addPage(new Security, i18n("Security"), "security-high");
00181     dialog->setHelp(QString(),"krfb");
00182     connect(dialog, SIGNAL(settingsChanged(QString)),KrfbServer::self(),SLOT(updateSettings()));
00183     dialog->show();
00184 }
00185 
00186 void ManageInvitationsDialog::deleteAll()
00187 {
00188     if (KMessageBox::warningContinueCancel(this,
00189         i18n("<qt>Are you sure you want to delete all invitations?</qt>"),
00190         i18n("Confirm delete Invitations"),
00191         KStandardGuiItem::ok(),
00192         KStandardGuiItem::cancel(),
00193         QString("krfbdeleteallinv")) !=
00194         KMessageBox::Continue)
00195     {
00196         return;
00197     }
00198 
00199     InvitationManager::self()->removeAllInvitations();
00200 }
00201 
00202 void ManageInvitationsDialog::deleteCurrent()
00203 {
00204     if (KMessageBox::warningContinueCancel(this,
00205         i18n("<qt>Are you sure you want to delete this invitation?</qt>"),
00206         i18n("Confirm delete Invitations"),
00207         KStandardGuiItem::ok(),
00208         KStandardGuiItem::cancel(),
00209         QString("krfbdeleteoneinv")) !=
00210         KMessageBox::Continue)
00211     {
00212         return;
00213     }
00214 
00215     // disable updates while deleting items, otherwise the list would invalidate itself
00216     disconnect(InvitationManager::self(), SIGNAL(invitationNumChanged(int)),
00217                this, SLOT(reloadInvitations()));
00218 
00219     QList<QTreeWidgetItem *> itl = invitationWidget->selectedItems();
00220     foreach(QTreeWidgetItem *itm, itl) {
00221         foreach(const Invitation &inv, InvitationManager::self()->invitations()) {
00222             if (inv.creationTime() == itm->data(0,Qt::UserRole+1)) {
00223                 InvitationManager::self()->removeInvitation(inv);
00224             }
00225         }
00226     }
00227 
00228     // update it manually
00229     reloadInvitations();
00230 
00231     connect(InvitationManager::self(), SIGNAL(invitationNumChanged(int)),
00232             SLOT(reloadInvitations()));
00233 }
00234 
00235 void ManageInvitationsDialog::selectionChanged()
00236 {
00237     deleteOneButton->setEnabled(invitationWidget->selectedItems().size() > 0);
00238 }
00239 

krfb

Skip menu "krfb"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdenetwork

Skip menu "kdenetwork"
  • kget
  • kopete
  •   kopete
  •   libkopete
  •       libpapillon
  • krfb
Generated for kdenetwork by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal