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

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