[PATCH] kicker+kdesktop[_lock] (Re: Start new session...)

Oswald Buddenhagen ossi at kde.org
Fri Oct 11 05:28:13 BST 2002


ok, here's the result.
the bad news first: we can't even show the current vt number, as we cannot
be sure of having console access (in fact, we can be almost sure to have
none).
the kdesktop_lock part became "somewhat" bigger than expected, as i had
to implement half of kmessagebox's functionality. i also tried to clean
up the kcheckpass failure case at this occasion.

oh, by the way, this whole code is specific to linux, so maybe put it in
#ifdef __linux__. but then there are rumours, that freebsd also has
virtual consoles - but i don't know how they are used up to this day.

ok to commit?

greetings

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!
--
Chaos, panic, and disorder - my work here is done.
-------------- next part --------------
Index: kicker/ui/k_mnu.cpp
===================================================================
RCS file: /home/kde/kdebase/kicker/ui/k_mnu.cpp,v
retrieving revision 1.67
diff -u -r1.67 k_mnu.cpp
--- kicker/ui/k_mnu.cpp	2002/10/06 20:43:31	1.67
+++ kicker/ui/k_mnu.cpp	2002/10/11 04:11:34
@@ -43,6 +43,7 @@
 #include <konqbookmarkmanager.h>
 #include <kbookmarkmenu.h>
 #include <kstandarddirs.h>
+#include <kmessagebox.h>
 #include <kdebug.h>
 
 #include "k_mnu.h"
@@ -350,6 +351,18 @@
 
 void PanelKMenu::slotNewSession()
 {
+    if (KMessageBox::warningContinueCancel(
+	  kapp->desktop()->screen(kapp->desktop()->screenNumber(this)),
+          i18n("<p>You have chosen to open another desktop session.<br>"
+               "The current session will be hidden "
+               "and a new login screen will be displayed.<br>"
+               "An F-key is assigned to each session; "
+               "F%1 is usually assigned to the first session, "
+               "F%2 to the second session and so on. "
+               "You can switch between sessions by pressing "
+               "CTRL, ALT and the appropriate F-key at the same time.</p>")
+            .arg(7).arg(8)) != KMessageBox::Continue)
+        return;
     QFile fifo(xdmFifoName);
     if (fifo.open(IO_WriteOnly | IO_Raw)) {
         fifo.writeBlock( "reserve\n", 8 );
Index: kdesktop/krootwm.cc
===================================================================
RCS file: /home/kde/kdebase/kdesktop/krootwm.cc,v
retrieving revision 1.164
diff -u -r1.164 krootwm.cc
--- kdesktop/krootwm.cc	2002/10/06 20:43:31	1.164
+++ kdesktop/krootwm.cc	2002/10/11 04:11:35
@@ -47,6 +47,7 @@
 #include <kdebug.h>
 #include <kwindowlistmenu.h>
 #include <kmenubar.h>
+#include <kmessagebox.h>
 #include <qfile.h>
 
 #include "krootwm.h"
@@ -626,6 +627,17 @@
 }
 
 void KRootWm::slotNewSession() {
+    if (KMessageBox::warningContinueCancel(m_pDesktop,
+          i18n("<p>You have chosen to open another desktop session.<br>"
+               "The current session will be hidden "
+               "and a new login screen will be displayed.<br>"
+               "An F-key is assigned to each session; "
+               "F%1 is usually assigned to the first session, "
+               "F%2 to the second session and so on. "
+               "You can switch between sessions by pressing "
+               "CTRL, ALT and the appropriate F-key at the same time.</p>")
+            .arg(7).arg(8)) != KMessageBox::Continue)
+        return;
     QFile fifo(xdmFifoName);
     if (fifo.open(IO_WriteOnly | IO_Raw)) {
         fifo.writeBlock( "reserve\n", 8 );
Index: kdesktop/lock/lockdlg.cc
===================================================================
RCS file: /home/kde/kdebase/kdesktop/lock/lockdlg.cc,v
retrieving revision 1.4
diff -u -r1.4 lockdlg.cc
--- kdesktop/lock/lockdlg.cc	2002/10/06 03:30:20	1.4
+++ kdesktop/lock/lockdlg.cc	2002/10/11 04:11:35
@@ -12,6 +12,8 @@
 #include <qlayout.h>
 #include <qframe.h>
 #include <qpushbutton.h>
+#include <qmessagebox.h>
+#include <qsimplerichtext.h>
 #include <klocale.h>
 #include <kstandarddirs.h>
 #include <kglobalsettings.h>
@@ -69,7 +71,7 @@
     if (nsess) {
 	mButton = new QPushButton(i18n("\nStart\n&New\nSession\n"), winFrame, "button");
 	layout->addMultiCellWidget(mButton, 0,1, 3,3, AlignCenter);
-	connect(mButton, SIGNAL(clicked()), SIGNAL(startNewSession()));
+	connect(mButton, SIGNAL(clicked()), SLOT(slotStartNewSession()));
 	mButton->installEventFilter(this);
     } else
 	mButton = 0;
@@ -226,11 +228,12 @@
 	    */
         if (mPassProc.normalExit() && !mPassProc.exitStatus())
         {
+	    accept();
+        }
+        else if ( mPassProc.exitStatus() == 2 )
+	{
 /*
 XXX this needs to go into a separate routine at startup time
-            stopSaver();
-	    if ( mPassProc.exitStatus() == 2 )
-	    {
 		KMessageBox::error(0,
 		  i18n( "<h1>Screen Locking Failed!</h1>"
 		  "Your screen was not locked because the <i>kcheckpass</i> "
@@ -240,11 +243,11 @@
 		  "kcheckpass as root. If you are using a pre-compiled "
 		  "package, contact the packager." ),
 		  i18n( "Screen Locking Failed" ) );
-	    }
-	    kapp->quit();
 */
-	    accept();
-        }
+            kdDebug(1204) << "kcheckpass cannot verify password. not setuid root?" << endl;
+            mLabel->setText(i18n("Verification failed\nKill kdesktop_lock"));
+            mFailedTimerId = startTimer(10000);
+	}
         else
         {
             mLabel->setText(i18n("Failed"));
@@ -272,4 +275,109 @@
     }
     setActiveWindow();
     setFocus();
+}
+
+void PasswordDlg::slotStartNewSession()
+{
+    killTimer(mTimeoutTimerId);
+
+    QDialog *dialog = new QDialog( this, "warnbox", true, WStyle_Customize | WStyle_NoBorder );
+    QFrame *winFrame = new QFrame( dialog );
+    winFrame->setFrameStyle( QFrame::WinPanel | QFrame::Raised );
+    winFrame->setLineWidth( 2 );
+    QVBoxLayout *vbox = new QVBoxLayout( dialog );
+    vbox->addWidget( winFrame );
+
+    QLabel *label1 = new QLabel( winFrame );
+    label1->setPixmap( QMessageBox::standardIcon( QMessageBox::Warning ) );
+    QString qt_text = 
+          i18n("You have chosen to open another desktop session "
+               "instead of resuming the current one.<br>"
+               "The current session will be hidden "
+               "and a new login screen will be displayed.<br>"
+               "An F-key is assigned to each session; "
+               "F%1 is usually assigned to the first session, "
+               "F%2 to the second session and so on. "
+               "You can switch between sessions by pressing "
+               "CTRL, ALT and the appropriate F-key at the same time.")
+            .arg(7).arg(8);
+    QLabel *label2 = new QLabel( qt_text, winFrame );
+    QPushButton *okbutton = new QPushButton( KStdGuiItem::cont().text(), winFrame );
+    okbutton->setDefault( true );
+    connect( okbutton, SIGNAL( clicked() ), dialog, SLOT( accept() ) );
+    QPushButton *cbutton = new QPushButton( KStdGuiItem::cancel().text(), winFrame );
+    connect( cbutton, SIGNAL( clicked() ), dialog, SLOT( reject() ) );
+
+    QBoxLayout *hbox = new QHBoxLayout( 0 );
+    hbox->addStretch( 1 );
+    hbox->addWidget( okbutton );
+    hbox->addStretch( 1 );
+    hbox->addWidget( cbutton );
+    hbox->addStretch( 1 );
+
+    QGridLayout *grid = new QGridLayout( winFrame, 2, 2, 10 );
+    grid->addWidget( label1, 0, 0, Qt::AlignCenter );
+    grid->addWidget( label2, 0, 1, Qt::AlignCenter );
+    grid->addMultiCellLayout( hbox, 1,1, 0,1 );
+
+    // stolen from kmessagebox
+    int pref_width = 0;
+    int pref_height = 0;
+    // Calculate a proper size for the text.
+    {
+       QSimpleRichText rt(qt_text, dialog->font());
+       int scr = QApplication::desktop()->screenNumber(dialog);
+
+       pref_width = QApplication::desktop()->screenGeometry(scr).width() / 3;
+       rt.setWidth(pref_width);
+       int used_width = rt.widthUsed();
+       pref_height = rt.height();
+       if (used_width <= pref_width)
+       {
+          while(true)
+          {
+             int new_width = (used_width * 9) / 10;
+             rt.setWidth(new_width);
+             int new_height = rt.height();
+             if (new_height > pref_height)
+                break;
+             used_width = rt.widthUsed();
+             if (used_width > new_width)
+                break;
+          }
+          pref_width = used_width;
+       }
+       else
+       {
+          if (used_width > (pref_width *2))
+             pref_width = pref_width *2;
+          else
+             pref_width = used_width;
+       }
+    }
+    label2->setFixedSize(QSize(pref_width+10, pref_height));
+
+    dialog->show();
+    QApplication::flushX();
+    for(;;)
+    { // wait for the window to get mapped
+        XWindowAttributes attrs;
+        if( XGetWindowAttributes( qt_xdisplay(), dialog->winId(), &attrs )
+            && attrs.map_state != IsUnmapped )
+            break;
+    }
+    dialog->setActiveWindow();
+    dialog->setFocus();
+
+    int ret = dialog->exec();
+
+    delete dialog;
+
+    setActiveWindow();
+    mEntry->setFocus();
+
+    if (ret == QDialog::Accepted)
+	emit startNewSession();
+
+    mTimeoutTimerId = startTimer(PASSDLG_HIDE_TIMEOUT);
 }
Index: kdesktop/lock/lockdlg.h
===================================================================
RCS file: /home/kde/kdebase/kdesktop/lock/lockdlg.h,v
retrieving revision 1.2
diff -u -r1.2 lockdlg.h
--- kdesktop/lock/lockdlg.h	2002/10/03 12:24:21	1.2
+++ kdesktop/lock/lockdlg.h	2002/10/11 04:11:35
@@ -38,6 +38,7 @@
 
 protected slots:
     void passwordChecked(KProcess *);
+    void slotStartNewSession();
 
 private:
     void startCheckPassword();


More information about the kde-core-devel mailing list