source: lumina/lumina-desktop/panel-plugins/systemtray/LSysTray.cpp @ 9d0ec76

releng/10.0.3
Last change on this file since 9d0ec76 was 9d0ec76, checked in by Ken Moore <ken@…>, 3 months ago

Update lumina-desktop to use the new abilities in LuminaOS instead of the GLobals.h file. Now all the OS-specific stuff is contained in a single location.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1//===========================================
2//  Lumina-DE source code
3//  Copyright (c) 2012, Ken Moore
4//  Available under the 3-clause BSD license
5//  See the LICENSE file for full details
6//===========================================
7#include "LSysTray.h"
8
9LSysTray::LSysTray(QWidget *parent, QString id, bool horizontal) : LPPlugin(parent, id, horizontal){
10  frame = new QFrame(this);
11  frame->setContentsMargins(0,0,0,0);
12  frame->setStyleSheet("QFrame{ background: black; border: 1px solid transparent; border-radius: 5px; }");
13  LI = new QBoxLayout( this->layout()->direction(), this);
14    frame->setLayout(LI);
15    LI->setAlignment(Qt::AlignCenter);
16    LI->setSpacing(1);
17    LI->setContentsMargins(0,0,0,0);
18  this->layout()->addWidget(frame);
19  this->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
20  isRunning = false;
21  start();
22}
23
24LSysTray::~LSysTray(){
25 if(isRunning){
26   this->stop();
27 }
28}
29
30void LSysTray::start(){
31  if(LSession::StartupSystemTray()){
32    //Now connect the application signals to the X event parser
33    connect(LSession::instance(),SIGNAL(NewSystemTrayApp(WId)),this,SLOT(addTrayIcon(WId)) );
34    qDebug() << "System Tray Started Successfully";
35    isRunning = true;
36  }
37}
38
39void LSysTray::stop(){
40  if(!isRunning){ return; }
41  //Release all the tray applications and delete the containers
42  for(int i=(trayIcons.length()-1); i>=0; i--){
43    trayIcons[i]->detachApp();
44    delete trayIcons.takeAt(i);
45  }
46  //Now close down the tray
47  LSession::CloseSystemTray();
48
49  disconnect(this);
50  isRunning = false;
51}
52
53// ========================
54//    PRIVATE FUNCTIONS
55// ========================
56void LSysTray::addTrayIcon(WId win){
57  if(win == 0 || !isRunning){ return; }
58  //qDebug() << "System Tray: Add Tray Icon:" << win;
59  bool exists = false;
60  for(int i=0; i<trayIcons.length(); i++){
61    if(trayIcons[i]->appID() == win){ exists=true; break; }
62  }
63  if(!exists){
64    //qDebug() << " - New Icon";
65    TrayIcon *cont = new TrayIcon(this);
66      QCoreApplication::processEvents();
67      connect(cont, SIGNAL(AppClosed()), this, SLOT(trayAppClosed()) );
68      connect(cont, SIGNAL(AppAttached()), this, SLOT(updateStatus()) );
69      trayIcons << cont;
70      LI->addWidget(cont);
71      if(this->layout()->direction()==QBoxLayout::LeftToRight){
72        cont->setSizeSquare(this->height()-2*frame->frameWidth()); //horizontal tray
73        this->setMaximumSize( trayIcons.length()*this->height(), 10000);
74      }else{
75        cont->setSizeSquare(this->width()-2*frame->frameWidth()); //vertical tray
76        this->setMaximumSize(10000, trayIcons.length()*this->width());
77      }
78      QCoreApplication::processEvents();
79      cont->attachApp(win);
80    LI->update(); //make sure there is no blank space
81  }
82}
83
84void LSysTray::updateStatus(){
85  qDebug() << "System Tray: Client Attached";
86  LI->update(); //make sure there is no blank space
87  //qDebug() << " - Items:" << trayIcons.length();
88}
89
90void LSysTray::trayAppClosed(){
91  for(int i=0;  i<trayIcons.length(); i++){
92    if(trayIcons[i]->appID() == 0){
93      qDebug() << "System Tray: Removing icon";
94      TrayIcon *cont = trayIcons.takeAt(i);
95      LI->removeWidget(cont);
96      delete cont;
97      QCoreApplication::processEvents();
98    }
99  }
100  //Re-adjust the maximum widget size
101  if(this->layout()->direction()==QBoxLayout::LeftToRight){
102    this->setMaximumSize( trayIcons.length()*this->height(), 10000);
103  }else{
104    this->setMaximumSize(10000, trayIcons.length()*this->width());
105  }
106  LI->update(); //update the layout (no gaps)
107  this->update();       
108}
109
Note: See TracBrowser for help on using the repository browser.