source: lumina/lumina-desktop/LSession.cpp @ 130bc0e

releng/10.0.3releng/10.1releng/10.1.1releng/10.1.2
Last change on this file since 130bc0e was 130bc0e, checked in by Ken Moore <ken@…>, 10 months ago

Get the Lumina Desktop Plugin system working completely. It is still a bit ugly and needs a visual update to the "unlocked" plugin container, but at least it works fine right now.

  • Property mode set to 100644
File size: 6.4 KB
Line 
1//===========================================
2//  Lumina-DE source code
3//  Copyright (c) 2012-2014, Ken Moore
4//  Available under the 3-clause BSD license
5//  See the LICENSE file for full details
6//===========================================
7#include "LSession.h"
8
9//Private/global variables (for static function access)
10WId LuminaSessionTrayID;
11AppMenu *appmenu;
12SettingsMenu *settingsmenu;
13QTranslator *currTranslator;
14
15LSession::LSession(int &argc, char ** argv) : QApplication(argc, argv){
16  this->setApplicationName("Lumina Desktop Environment");
17  this->setApplicationVersion("0.4.2");
18  this->setOrganizationName("LuminaDesktopEnvironment");
19  this->setQuitOnLastWindowClosed(false); //since the LDesktop's are not necessarily "window"s
20  //Enabled a few of the simple effects by default
21  this->setEffectEnabled( Qt::UI_AnimateMenu, true);
22  this->setEffectEnabled( Qt::UI_AnimateCombo, true);
23  this->setEffectEnabled( Qt::UI_AnimateTooltip, true);
24  LuminaSessionTrayID = 0;
25}
26
27LSession::~LSession(){
28  delete settingsmenu;
29  delete appmenu;
30}
31
32void LSession::setupSession(){
33  qDebug() << "Initializing Session";
34  loadStyleSheet();
35  //Setup the QSettings default paths
36  QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, QDir::homePath()+"/.lumina");
37 
38  checkUserFiles(); //copy/initialize any files necessary
39       
40  //Initialize the global menus
41  appmenu = new AppMenu();
42  settingsmenu = new SettingsMenu();
43}
44
45bool LSession::LoadLocale(QString langCode){
46    QTranslator translator;
47    if ( ! QFile::exists(SYSTEM::installDir()+"i18n/lumina-desktop_" + langCode + ".qm" ) )  langCode.truncate(langCode.indexOf("_"));
48    bool ok = translator.load( QString("lumina-desktop_") + langCode, SYSTEM::installDir()+"i18n/" );
49    if(ok){
50      //Remove any old translator
51      if(currTranslator != 0){ this->removeTranslator(currTranslator); }
52      //Insert the new translator
53      currTranslator = &translator;
54      this->installTranslator( currTranslator );
55      qDebug() << "Loaded Locale:" << langCode;
56    }else{
57      qDebug() << "Invalid Locale:" << langCode;
58    }
59    emit LocaleChanged();
60    return ok;
61}
62
63void LSession::launchStartupApps(){
64  QString startfile = QDir::homePath()+"/.lumina/startapps";
65  if(!QFile::exists(startfile)){ startfile = "/usr/local/share/Lumina-DE/startapps"; }
66  if(!QFile::exists(startfile)){ return; }
67  qDebug() << "Launching startup applications";
68  QFile file(startfile);
69  if( file.open(QIODevice::ReadOnly | QIODevice::Text) ){
70    QTextStream in(&file);
71    while(!in.atEnd()){
72      QString entry = in.readLine();
73      if(entry.startsWith("#") || entry.isEmpty()){ continue; }
74      //Might put other sanity checks here
75      QProcess::startDetached(entry);
76    }
77    file.close();
78  }
79}
80
81void LSession::checkUserFiles(){
82  //Check for the desktop settings file
83  QString dset = QDir::homePath()+"/.lumina/LuminaDE/desktopsettings.conf";
84  bool firstrun = false;
85  if(!QFile::exists(dset)){
86    firstrun = true;
87    if(QFile::exists(SYSTEM::installDir()+"desktopsettings.conf")){
88      if( QFile::copy(SYSTEM::installDir()+"desktopsettings.conf", dset) ){
89        QFile::setPermissions(dset, QFile::ReadUser | QFile::WriteUser | QFile::ReadOwner | QFile::WriteOwner);
90      }
91    }
92  }
93  //Check for the default applications file for lumina-open
94  dset = QDir::homePath()+"/.lumina/LuminaDE/lumina-open.conf";
95  if(!QFile::exists(dset)){
96    firstrun = true;
97    if(QFile::exists(SYSTEM::installDir()+"defaultapps.conf")){
98      if( QFile::copy(SYSTEM::installDir()+"defaultapps.conf", dset) ){
99        QFile::setPermissions(dset, QFile::ReadUser | QFile::WriteUser | QFile::ReadOwner | QFile::WriteOwner);
100      }
101    }
102  }
103  if(firstrun){ qDebug() << "First time using Lumina!!"; }
104}
105
106void LSession::loadStyleSheet(){
107  QString ss = QDir::homePath()+"/.lumina/stylesheet.qss";
108  if(!QFile::exists(ss)){ ss = SYSTEM::installDir()+"stylesheet.qss"; }
109  if(!QFile::exists(ss)){ return; } //no default stylesheet on the system
110  //Now read/apply the custom stylesheet
111  QFile file(ss);
112  if( file.open(QIODevice::ReadOnly | QIODevice::Text) ){
113    QTextStream in(&file);
114    QString sheet = in.readAll();
115    file.close();
116    //Now fix/apply the sheet
117      sheet.replace("\n"," "); //make sure there are no newlines
118    this->setStyleSheet(sheet);
119  }
120 
121}
122
123bool LSession::x11EventFilter(XEvent *event){
124  //Detect X Event types and send the appropriate signal(s)
125   switch(event->type){
126  // -------------------------
127    case ClientMessage:
128        //Only check if the client is the system tray, otherwise ignore
129        if(event->xany.window == LuminaSessionTrayID){
130          //qDebug() << "SysTray: ClientMessage";
131          parseClientMessageEvent(&(event->xclient));
132        }
133        break;
134    case SelectionClear:
135        if(event->xany.window == LuminaSessionTrayID){
136          //qDebug() << "SysTray: Selection Clear";
137          this->CloseSystemTray();
138        }
139        break;
140    case PropertyNotify:
141        //qDebug() << "Property Event:";
142        if(LX11::ValidWindowEvent(event->xproperty.atom)){
143          //qDebug() << " - Emit Window Event";
144          emit WindowListEvent();
145        }
146        break;
147  }
148  // -----------------------
149  //Now continue on with the event handling (don't change it)
150  return false;
151}
152
153//=================
154//   SYSTEM TRAY
155//=================
156bool LSession::StartupSystemTray(){
157  if(LuminaSessionTrayID != 0){ return false; } //already have one running
158  LuminaSessionTrayID = LX11::startSystemTray();
159  return (LuminaSessionTrayID != 0);
160}
161
162bool LSession::CloseSystemTray(){
163  LX11::closeSystemTray(LuminaSessionTrayID);
164  LuminaSessionTrayID = 0;
165  return true; //no additional checks for success at the moment
166}
167
168void LSession::parseClientMessageEvent(XClientMessageEvent *event){
169  unsigned long opcode = event->data.l[1];
170  switch(opcode){
171    case SYSTEM_TRAY_REQUEST_DOCK:
172        emit NewSystemTrayApp(event->data.l[2]); //Window ID
173        break;
174    case SYSTEM_TRAY_BEGIN_MESSAGE:
175        //Let the window manager handle the pop-up messages for now
176        break;             
177    case SYSTEM_TRAY_CANCEL_MESSAGE:
178        //Let the window manager handle the pop-up messages for now
179        break;
180    /*default:
181        //Unknown system tray operation code
182        opcode=1; //junk operation for compiling purposes*/
183  }
184}
185
186//===============
187//  SYSTEM ACCESS
188//===============
189AppMenu* LSession::applicationMenu(){
190  return appmenu;
191}
192
193SettingsMenu* LSession::settingsMenu(){
194  return settingsmenu;
195}
196
197void LSession::systemWindow(){
198  SystemWindow win;
199  win.exec();
200}
Note: See TracBrowser for help on using the repository browser.