void PanelKMenu::doNewSession( bool lock ) { int result = 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. " "Additionally, the KDE Panel and Desktop menus have " "actions for switching between sessions.</p>", 7, 8), i18n("Warning - New Session"), KGuiItem(i18n("&Start New Session"), "fork"), KStandardGuiItem::cancel(), ":confirmNewSession", KMessageBox::PlainCaption | KMessageBox::Notify); if (result==KMessageBox::Cancel) return; if (lock) slotLock(); KDisplayManager().startReserve(); }
void KSMServer::cleanUp() { if (clean) return; clean = true; IceFreeListenObjs (numTransports, listenObjs); QByteArray fName = QFile::encodeName(KStandardDirs::locateLocal("socket", "KSMserver")); QString display = QString::fromLocal8Bit(::getenv("DISPLAY")); // strip the screen number from the display display.replace(QRegExp("\\.[0-9]+$"), ""); int i; while( (i = display.indexOf(':')) >= 0) display[i] = '_'; while( (i = display.indexOf('/')) >= 0) display[i] = '_'; fName += '_'+display.toLocal8Bit(); ::unlink(fName.data()); FreeAuthenticationData(numTransports, authDataEntries); signal(SIGTERM, SIG_DFL); signal(SIGINT, SIG_DFL); KDisplayManager().shutdown( shutdownType, shutdownMode, bootOption ); }
void PanelKMenu::slotSessionActivated( int ent ) { if (ent == 100) doNewSession( true ); else if (ent == 101) doNewSession( false ); else if (!sessionsMenu->isItemChecked( ent )) KDisplayManager().lockSwitchVT( ent ); }
void PanelKMenu::initialize() { // kDebug(1210) << "PanelKMenu::initialize()"; updateRecent(); if (initialized()) { return; } if (loadSidePixmap()) { // in case we've been through here before, let's disconnect disconnect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), this, SLOT(paletteChanged())); connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), this, SLOT(paletteChanged())); } else { sidePixmap = sideTilePixmap = QPixmap(); } // add services PanelServiceMenu::initialize(); /* FIXME: no more insertTitle! now what? if (KickerSettings::showMenuTitles()) { int id; id = insertTitle(i18n("All Applications"), -1, 0); setItemEnabled( id, false ); id = insertTitle(i18n("Actions"), -1 , -1); setItemEnabled( id, false ); } */ // create recent menu section createRecentMenuItems(); bool need_separator = false; // insert bookmarks if (KickerSettings::useBookmarks() && KAuthorized::authorizeKAction("bookmarks")) { // Need to create a new popup each time, it's deleted by subMenus.clear() KMenu * bookmarkParent = new KMenu(this); bookmarkParent->setObjectName("bookmarks" ); delete bookmarkMenu; // can't reuse old one, the popup has been deleted bookmarkMenu = new KBookmarkMenu( KBookmarkManager::userBookmarksManager(), 0, bookmarkParent, actionCollection ); insertItem(Plasma::menuIconSet("bookmark"), i18n("Bookmarks"), bookmarkParent); subMenus.append(bookmarkParent); need_separator = true; } // insert quickbrowser if (KickerSettings::useBrowser()) { PanelQuickBrowser *browserMnu = new PanelQuickBrowser(this); browserMnu->initialize(); insertItem(Plasma::menuIconSet("kdisknav"), i18n("Quick Browser"), Plasma::reduceMenu(browserMnu)); subMenus.append(browserMnu); need_separator = true; } // insert dynamic menus QStringList menu_ext = KickerSettings::menuExtensions(); if (!menu_ext.isEmpty()) { for (QStringList::ConstIterator it=menu_ext.begin(); it!=menu_ext.end(); ++it) { MenuInfo info(*it); if (!info.isValid()) continue; KPanelMenu *menu = info.load(); if (menu) { insertItem(Plasma::menuIconSet(info.icon()), info.name(), menu); dynamicSubMenus.append(menu); need_separator = true; } } } if (need_separator) addSeparator(); // run command if (KAuthorized::authorizeKAction("run_command")) { insertItem(Plasma::menuIconSet("system-run"), i18n("Run Command..."), this, SLOT( slotRunCommand())); addSeparator(); } if (KDisplayManager().isSwitchable() && KAuthorized::authorizeKAction("switch_user")) { sessionsMenu = new QMenu( this ); insertItem(Plasma::menuIconSet("switchuser"), i18n("Switch User"), sessionsMenu); connect( sessionsMenu, SIGNAL(aboutToShow()), SLOT(slotPopulateSessions()) ); connect( sessionsMenu, SIGNAL(activated(int)), SLOT(slotSessionActivated(int)) ); } /* If the user configured ksmserver to */ KConfig ksmserver("ksmserverrc", KConfig::CascadeConfig); if (ksmserver.group("General").readEntry( "loginMode" ) == "restoreSavedSession") { insertItem(Plasma::menuIconSet("document-save"), i18n("Save Session"), this, SLOT(slotSaveSession())); } if (KAuthorized::authorizeKAction("lock_screen")) { insertItem(Plasma::menuIconSet("system-lock-screen"), i18n("Lock Session"), this, SLOT(slotLock())); } if (KAuthorized::authorizeKAction("logout")) { insertItem(Plasma::menuIconSet("application-exit"), i18n("Log Out..."), this, SLOT(slotLogout())); } #if 0 // WABA: tear off handles don't work together with dynamically updated // menus. We can't update the menu while torn off, and we don't know // when it is torn off. if (KGlobalSettings::insertTearOffHandle()) insertTearOffHandle(); #endif setInitialized(true); }
KSMShutdownDlg::KSMShutdownDlg( QWindow* parent, bool maysd, bool choose, KWorkSpace::ShutdownType sdtype, const QString& theme) : QQuickView(parent), m_result(false) // this is a WType_Popup on purpose. Do not change that! Not // having a popup here has severe side effects. { // window stuff setClearBeforeRendering(true); setColor(QColor(Qt::transparent)); setFlags(Qt::FramelessWindowHint | Qt::BypassWindowManagerHint); QPoint globalPosition(QCursor::pos()); foreach (QScreen *s, QGuiApplication::screens()) { if (s->geometry().contains(globalPosition)) { setScreen(s); break; } } // Qt doesn't set this on unmanaged windows //FIXME: or does it? XChangeProperty( QX11Info::display(), winId(), XInternAtom( QX11Info::display(), "WM_WINDOW_ROLE", False ), XA_STRING, 8, PropModeReplace, (unsigned char *)"logoutdialog", strlen( "logoutdialog" )); //QQuickView *windowContainer = QQuickView::createWindowContainer(m_view, this); //windowContainer->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); QQmlContext *context = rootContext(); context->setContextProperty(QStringLiteral("maysd"), maysd); context->setContextProperty(QStringLiteral("choose"), choose); context->setContextProperty(QStringLiteral("sdtype"), sdtype); QQmlPropertyMap *mapShutdownType = new QQmlPropertyMap(this); mapShutdownType->insert(QStringLiteral("ShutdownTypeDefault"), QVariant::fromValue<int>(KWorkSpace::ShutdownTypeDefault)); mapShutdownType->insert(QStringLiteral("ShutdownTypeNone"), QVariant::fromValue<int>(KWorkSpace::ShutdownTypeNone)); mapShutdownType->insert(QStringLiteral("ShutdownTypeReboot"), QVariant::fromValue<int>(KWorkSpace::ShutdownTypeReboot)); mapShutdownType->insert(QStringLiteral("ShutdownTypeHalt"), QVariant::fromValue<int>(KWorkSpace::ShutdownTypeHalt)); mapShutdownType->insert(QStringLiteral("ShutdownTypeLogout"), QVariant::fromValue<int>(KWorkSpace::ShutdownTypeLogout)); context->setContextProperty(QStringLiteral("ShutdownType"), mapShutdownType); QQmlPropertyMap *mapSpdMethods = new QQmlPropertyMap(this); QSet<Solid::PowerManagement::SleepState> spdMethods = Solid::PowerManagement::supportedSleepStates(); mapSpdMethods->insert(QStringLiteral("StandbyState"), QVariant::fromValue(spdMethods.contains(Solid::PowerManagement::StandbyState))); mapSpdMethods->insert(QStringLiteral("SuspendState"), QVariant::fromValue(spdMethods.contains(Solid::PowerManagement::SuspendState))); mapSpdMethods->insert(QStringLiteral("HibernateState"), QVariant::fromValue(spdMethods.contains(Solid::PowerManagement::HibernateState))); context->setContextProperty(QStringLiteral("spdMethods"), mapSpdMethods); QString bootManager = KConfig(QStringLiteral(KDE_CONFDIR "/kdm/kdmrc"), KConfig::SimpleConfig) .group("Shutdown") .readEntry("BootManager", "None"); context->setContextProperty(QStringLiteral("bootManager"), bootManager); QStringList options; int def, cur; if ( KDisplayManager().bootOptions( rebootOptions, def, cur ) ) { if ( cur > -1 ) { def = cur; } } QQmlPropertyMap *rebootOptionsMap = new QQmlPropertyMap(this); rebootOptionsMap->insert(QStringLiteral("options"), QVariant::fromValue(rebootOptions)); rebootOptionsMap->insert(QStringLiteral("default"), QVariant::fromValue(def)); context->setContextProperty(QStringLiteral("rebootOptions"), rebootOptionsMap); context->setContextProperty(QStringLiteral("screenGeometry"), screen()->geometry()); setModality(Qt::ApplicationModal); // engine stuff KDeclarative::KDeclarative kdeclarative; kdeclarative.setDeclarativeEngine(engine()); kdeclarative.initialize(); kdeclarative.setupBindings(); // windowContainer->installEventFilter(this); QString fileName; if(theme.isEmpty()) { KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel")); KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "KDE"); const QString packageName = cg.readEntry("LookAndFeelPackage", QString()); if (!packageName.isEmpty()) { package.setPath(packageName); } fileName = package.filePath("logoutmainscript"); } else fileName = theme; if (QFile::exists(fileName)) { //qCDebug(KSMSERVER) << "Using QML theme" << fileName; setSource(QUrl::fromLocalFile(fileName)); } else { qWarning() << "Couldn't find a theme for the Shutdown dialog" << fileName; return; } setPosition(screen()->virtualGeometry().center().x() - width() / 2, screen()->virtualGeometry().center().y() - height() / 2); if(!errors().isEmpty()) { qWarning() << errors(); } connect(rootObject(), SIGNAL(logoutRequested()), SLOT(slotLogout())); connect(rootObject(), SIGNAL(haltRequested()), SLOT(slotHalt())); connect(rootObject(), SIGNAL(suspendRequested(int)), SLOT(slotSuspend(int)) ); connect(rootObject(), SIGNAL(rebootRequested()), SLOT(slotReboot())); connect(rootObject(), SIGNAL(rebootRequested2(int)), SLOT(slotReboot(int)) ); connect(rootObject(), SIGNAL(cancelRequested()), SLOT(reject())); connect(rootObject(), SIGNAL(lockScreenRequested()), SLOT(slotLockScreen())); show(); requestActivate(); KWindowSystem::setState(winId(), NET::SkipTaskbar|NET::SkipPager); }
KSMShutdownDlg::KSMShutdownDlg( QWindow* parent, bool maysd, bool choose, KWorkSpace::ShutdownType sdtype, const QString& theme) : QQuickView(parent), //krazy:exclude=qclasses m_result(false) // this is a WType_Popup on purpose. Do not change that! Not // having a popup here has severe side effects. { // window stuff QSurfaceFormat format; format.setAlphaBufferSize(8); setFormat(format); setClearBeforeRendering(true); setColor(QColor(Qt::transparent)); setFlags(Qt::FramelessWindowHint); winId(); // workaround for Qt4.3 setWindowRole() assert // setWindowRole( QStringLiteral("logoutdialog") ); // Qt doesn't set this on unmanaged windows //FIXME: or does it? XChangeProperty( QX11Info::display(), winId(), XInternAtom( QX11Info::display(), "WM_WINDOW_ROLE", False ), XA_STRING, 8, PropModeReplace, (unsigned char *)"logoutdialog", strlen( "logoutdialog" )); setPosition(screen()->virtualGeometry().center().x() - width() / 2, screen()->virtualGeometry().center().y() - height() / 2); setMinimumSize(QSize(300, 200)); //kDebug() << "Creating QML view"; //QQuickView *windowContainer = QQuickView::createWindowContainer(m_view, this); //windowContainer->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); QQmlContext *context = rootContext(); context->setContextProperty(QStringLiteral("maysd"), maysd); context->setContextProperty(QStringLiteral("choose"), choose); context->setContextProperty(QStringLiteral("sdtype"), sdtype); QQmlPropertyMap *mapShutdownType = new QQmlPropertyMap(this); mapShutdownType->insert(QStringLiteral("ShutdownTypeDefault"), QVariant::fromValue((int)KWorkSpace::ShutdownTypeDefault)); mapShutdownType->insert(QStringLiteral("ShutdownTypeNone"), QVariant::fromValue((int)KWorkSpace::ShutdownTypeNone)); mapShutdownType->insert(QStringLiteral("ShutdownTypeReboot"), QVariant::fromValue((int)KWorkSpace::ShutdownTypeReboot)); mapShutdownType->insert(QStringLiteral("ShutdownTypeHalt"), QVariant::fromValue((int)KWorkSpace::ShutdownTypeHalt)); mapShutdownType->insert(QStringLiteral("ShutdownTypeLogout"), QVariant::fromValue((int)KWorkSpace::ShutdownTypeLogout)); context->setContextProperty(QStringLiteral("ShutdownType"), mapShutdownType); QQmlPropertyMap *mapSpdMethods = new QQmlPropertyMap(this); QSet<Solid::PowerManagement::SleepState> spdMethods = Solid::PowerManagement::supportedSleepStates(); mapSpdMethods->insert(QStringLiteral("StandbyState"), QVariant::fromValue(spdMethods.contains(Solid::PowerManagement::StandbyState))); mapSpdMethods->insert(QStringLiteral("SuspendState"), QVariant::fromValue(spdMethods.contains(Solid::PowerManagement::SuspendState))); mapSpdMethods->insert(QStringLiteral("HibernateState"), QVariant::fromValue(spdMethods.contains(Solid::PowerManagement::HibernateState))); context->setContextProperty(QStringLiteral("spdMethods"), mapSpdMethods); QString bootManager = KConfig(QStringLiteral(KDE_CONFDIR "/kdm/kdmrc"), KConfig::SimpleConfig) .group("Shutdown") .readEntry("BootManager", "None"); context->setContextProperty(QStringLiteral("bootManager"), bootManager); QStringList options; int def, cur; if ( KDisplayManager().bootOptions( rebootOptions, def, cur ) ) { if ( cur > -1 ) { def = cur; } } QQmlPropertyMap *rebootOptionsMap = new QQmlPropertyMap(this); rebootOptionsMap->insert(QStringLiteral("options"), QVariant::fromValue(rebootOptions)); rebootOptionsMap->insert(QStringLiteral("default"), QVariant::fromValue(def)); context->setContextProperty(QStringLiteral("rebootOptions"), rebootOptionsMap); setModality(Qt::ApplicationModal); // engine stuff KDeclarative::KDeclarative kdeclarative; kdeclarative.setDeclarativeEngine(engine()); kdeclarative.initialize(); kdeclarative.setupBindings(); // windowContainer->installEventFilter(this); QString fileName = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("ksmserver/themes/%1/main.qml").arg(theme)); if (QFile::exists(fileName)) { //kDebug() << "Using QML theme" << fileName; setSource(QUrl::fromLocalFile(fileName)); } connect(rootObject(), SIGNAL(logoutRequested()), SLOT(slotLogout())); connect(rootObject(), SIGNAL(haltRequested()), SLOT(slotHalt())); connect(rootObject(), SIGNAL(suspendRequested(int)), SLOT(slotSuspend(int)) ); connect(rootObject(), SIGNAL(rebootRequested()), SLOT(slotReboot())); connect(rootObject(), SIGNAL(rebootRequested2(int)), SLOT(slotReboot(int)) ); connect(rootObject(), SIGNAL(cancelRequested()), SLOT(reject())); connect(rootObject(), SIGNAL(lockScreenRequested()), SLOT(slotLockScreen())); show(); // adjustSize(); }