Back to index

lightdm  1.3.2
test-qt-greeter.cpp
Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include <stdio.h>
00003 #include <signal.h>
00004 #include <glib-object.h>
00005 #include <xcb/xcb.h>
00006 #include <QLightDM/Greeter>
00007 #include <QtCore/QSettings>
00008 #include <QtCore/QDebug>
00009 #include <QtCore/QCoreApplication>
00010 
00011 #include "test-qt-greeter.h"
00012 #include "status.h"
00013 
00014 static QSettings *config = NULL;
00015 static TestGreeter *greeter = NULL;
00016 
00017 TestGreeter::TestGreeter ()
00018 {
00019     connect (this, SIGNAL(showMessage(QString, QLightDM::Greeter::MessageType)), SLOT(showMessage(QString, QLightDM::Greeter::MessageType)));
00020     connect (this, SIGNAL(showPrompt(QString, QLightDM::Greeter::PromptType)), SLOT(showPrompt(QString, QLightDM::Greeter::PromptType)));
00021     connect (this, SIGNAL(authenticationComplete()), SLOT(authenticationComplete()));
00022 }
00023 
00024 void TestGreeter::showMessage (QString text, QLightDM::Greeter::MessageType type)
00025 {
00026     status_notify ("GREETER %s SHOW-MESSAGE TEXT=\"%s\"", getenv ("DISPLAY"), text.toAscii ().constData ());
00027 }
00028 
00029 void TestGreeter::showPrompt (QString text, QLightDM::Greeter::PromptType type)
00030 {
00031     status_notify ("GREETER %s SHOW-PROMPT TEXT=\"%s\"", getenv ("DISPLAY"), text.toAscii ().constData ());
00032 }
00033 
00034 void TestGreeter::authenticationComplete ()
00035 {
00036     if (authenticationUser () != "")
00037         status_notify ("GREETER %s AUTHENTICATION-COMPLETE USERNAME=%s AUTHENTICATED=%s",
00038                        getenv ("DISPLAY"),
00039                        authenticationUser ().toAscii ().constData (), isAuthenticated () ? "TRUE" : "FALSE");
00040     else
00041         status_notify ("GREETER %s AUTHENTICATION-COMPLETE AUTHENTICATED=%s", getenv ("DISPLAY"), isAuthenticated () ? "TRUE" : "FALSE");
00042 }
00043 
00044 static void
00045 signal_cb (int signum)
00046 {
00047     status_notify ("GREETER %s TERMINATE SIGNAL=%d", getenv ("DISPLAY"), signum);
00048     exit (EXIT_SUCCESS);
00049 }
00050 
00051 static void
00052 request_cb (const gchar *request)
00053 {
00054     gchar *r;
00055   
00056     r = g_strdup_printf ("GREETER %s AUTHENTICATE", getenv ("DISPLAY"));
00057     if (strcmp (request, r) == 0)
00058         greeter->authenticate ();
00059     g_free (r);
00060 
00061     r = g_strdup_printf ("GREETER %s AUTHENTICATE USERNAME=", getenv ("DISPLAY"));
00062     if (g_str_has_prefix (request, r))
00063         greeter->authenticate (request + strlen (r));
00064     g_free (r);
00065 
00066     r = g_strdup_printf ("GREETER %s AUTHENTICATE-GUEST", getenv ("DISPLAY"));
00067     if (strcmp (request, r) == 0)
00068         greeter->authenticateAsGuest ();
00069     g_free (r);
00070 
00071     r = g_strdup_printf ("GREETER %s RESPOND TEXT=\"", getenv ("DISPLAY"));
00072     if (g_str_has_prefix (request, r))
00073     {
00074         gchar *text = g_strdup (request + strlen (r));
00075         text[strlen (text) - 1] = '\0';
00076         greeter->respond (text);
00077         g_free (text);
00078     }
00079     g_free (r);
00080 
00081     r = g_strdup_printf ("GREETER %s START-SESSION", getenv ("DISPLAY"));
00082     if (strcmp (request, r) == 0)
00083     {
00084         if (!greeter->startSessionSync ())
00085             status_notify ("GREETER %s SESSION-FAILED", getenv ("DISPLAY"));
00086     }
00087     g_free (r);
00088 
00089     r = g_strdup_printf ("GREETER %s START-SESSION SESSION=", getenv ("DISPLAY"));
00090     if (g_str_has_prefix (request, r))
00091     {
00092         if (!greeter->startSessionSync (request + strlen (r)))
00093             status_notify ("GREETER %s SESSION-FAILED", getenv ("DISPLAY"));
00094     }
00095     g_free (r);
00096 }
00097 
00098 int
00099 main(int argc, char *argv[])
00100 {
00101     g_type_init ();
00102 
00103     status_connect (request_cb);
00104 
00105     QCoreApplication app(argc, argv);
00106 
00107     signal (SIGINT, signal_cb);
00108     signal (SIGTERM, signal_cb);
00109 
00110     status_notify ("GREETER %s START", getenv ("DISPLAY"));
00111 
00112     config = new QSettings (g_build_filename (getenv ("LIGHTDM_TEST_ROOT"), "script", NULL), QSettings::IniFormat);
00113 
00114     xcb_connection_t *connection = xcb_connect (NULL, NULL);
00115 
00116     if (xcb_connection_has_error (connection))
00117     {
00118         status_notify ("GREETER %s FAIL-CONNECT-XSERVER", getenv ("DISPLAY"));
00119         return EXIT_FAILURE;
00120     }
00121 
00122     status_notify ("GREETER %s CONNECT-XSERVER", getenv ("DISPLAY"));
00123 
00124     greeter = new TestGreeter();
00125   
00126     status_notify ("GREETER %s CONNECT-TO-DAEMON", getenv ("DISPLAY"));
00127     if (!greeter->connectSync())
00128     {
00129         status_notify ("GREETER %s FAIL-CONNECT-DAEMON", getenv ("DISPLAY"));
00130         return EXIT_FAILURE;
00131     }
00132 
00133     status_notify ("GREETER %s CONNECTED-TO-DAEMON", getenv ("DISPLAY"));
00134 
00135     if (greeter->selectUserHint() != "")
00136         status_notify ("GREETER %s SELECT-USER-HINT USERNAME=%s", getenv ("DISPLAY"), greeter->selectUserHint ().toAscii ().constData ());
00137     if (greeter->lockHint())
00138         status_notify ("GREETER %s LOCK-HINT", getenv ("DISPLAY"));
00139 
00140     return app.exec();
00141 }