From 9163f5e496cdb7e94f8e9b3e5b3dcb92ad2ef85f Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Thu, 11 Jan 2018 20:43:08 -0800 Subject: Fix up the saving of the current window positions in the backend objects. --- .../src-desktop/src-cpp/NativeWindowObject.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src-qt5') diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/NativeWindowObject.cpp b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/NativeWindowObject.cpp index 61a82e5c..dae4676c 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/NativeWindowObject.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/NativeWindowObject.cpp @@ -308,5 +308,8 @@ void NativeWindowObject::emitSinglePropChanged(NativeWindowObject::Property prop } void NativeWindowObject::sendNewGeom(){ -requestProperties(QList() << NativeWindowObject::GlobalPos << NativeWindowObject::Size, QList() << newgeom.topLeft() << newgeom.size()); + QList props; props << NativeWindowObject::GlobalPos << NativeWindowObject::Size; + QList vals; vals << newgeom.topLeft() << newgeom.size(); + requestProperties(props, vals); + setProperties(props,vals); } -- cgit From 9083f9a57b4414e0ad6f22127b156bc8581ef45c Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Fri, 12 Jan 2018 08:20:09 -0800 Subject: Add an additional OS-specific network device type parser. --- .../panel-plugins/battery/LBattery.cpp | 21 +++++++++++---------- src-qt5/src-cpp/framework-OSInterface-template.cpp | 17 +++++++++++------ src-qt5/src-cpp/framework-OSInterface.h | 3 ++- 3 files changed, 24 insertions(+), 17 deletions(-) (limited to 'src-qt5') diff --git a/src-qt5/core/lumina-desktop/panel-plugins/battery/LBattery.cpp b/src-qt5/core/lumina-desktop/panel-plugins/battery/LBattery.cpp index 69ea5faa..1870eefb 100644 --- a/src-qt5/core/lumina-desktop/panel-plugins/battery/LBattery.cpp +++ b/src-qt5/core/lumina-desktop/panel-plugins/battery/LBattery.cpp @@ -78,19 +78,20 @@ void LBattery::updateBattery(bool force){ break; } } - if(iconvalue("PlayBatteryLowAudio",true).toBool(); - if( playaudio ){ QString sfile = LSession::handle()->sessionSettings()->value("audiofiles/batterylow", LOS::LuminaShare()+"low-battery.ogg").toString(); + if(iconvalue("PlayBatteryLowAudio",true).toBool(); + if( playaudio ){ + QString sfile = LSession::handle()->sessionSettings()->value("audiofiles/batterylow", LOS::LuminaShare()+"low-battery.ogg").toString(); LSession::handle()->playAudioFile(sfile); - } + } + } - if(icon==0){ label->setStyleSheet("QLabel{ background: red;}"); } - else if(icon==14 && charge>98){ label->setStyleSheet("QLabel{ background: green;}"); } - else{ label->setStyleSheet("QLabel{ background: transparent;}"); } - iconOld = icon; + if(icon==0){ label->setStyleSheet("QLabel{ background: red;}"); } + else if(icon==14 && charge>98){ label->setStyleSheet("QLabel{ background: green;}"); } + else{ label->setStyleSheet("QLabel{ background: transparent;}"); } + iconOld = icon; - } //Now update the display QString tt; //Make sure the tooltip can be properly translated as necessary (Ken Moore 5/9/14) diff --git a/src-qt5/src-cpp/framework-OSInterface-template.cpp b/src-qt5/src-cpp/framework-OSInterface-template.cpp index 972e02e0..a1553857 100644 --- a/src-qt5/src-cpp/framework-OSInterface-template.cpp +++ b/src-qt5/src-cpp/framework-OSInterface-template.cpp @@ -45,6 +45,11 @@ QString OSInterface::networkType(){ return ""; } +QString OSInterface::networkTypeFromDeviceName(QString name){ + //Return options: wifi, wired, cell, cell-2G, cell-3G, cell-4G + return ""; +} + float OSInterface::networkStrength(){ return -1; } //percentage. ("wired" type should always be 100%) QString OSInterface::networkHostname(){ @@ -126,21 +131,21 @@ void OSInterface::netAccessChanged(QNetworkAccessManager::NetworkAccessibility s case QNetworkConfiguration::Bearer2G: type="cell-2G"; break; case QNetworkConfiguration::Bearer3G: type="cell-3G"; break; case QNetworkConfiguration::Bearer4G: type="cell-4G"; break; - default: type=""; + default: type=networkTypeFromDeviceName(active.name()); //could not be auto-determined - run the OS-specific routine } INFO.insert("netaccess/type", type); - qDebug() << "Detected Device Status:" << active.identifier() << type << stat; + //qDebug() << "Detected Device Status:" << active.identifier() << type << stat; QNetworkInterface iface = QNetworkInterface::interfaceFromName(active.name()); - qDebug() << " - Configuration: Name:" << active.name() << active.bearerTypeName() << active.identifier(); - qDebug() << " - Interface: MAC Address:" << iface.hardwareAddress() << "Name:" << iface.name() << iface.humanReadableName() << iface.isValid(); + //qDebug() << " - Configuration: Name:" << active.name() << active.bearerTypeName() << active.identifier(); + //qDebug() << " - Interface: MAC Address:" << iface.hardwareAddress() << "Name:" << iface.name() << iface.humanReadableName() << iface.isValid(); QList addressList = iface.addressEntries(); QStringList address; //NOTE: There are often 2 addresses, IPv4 and IPv6 for(int i=0; i Date: Sat, 13 Jan 2018 12:45:09 -0800 Subject: Another large checkpoint commit for Lumina 2: * Integrate the new window geometry manager class * Get the new OSInterface framework tied in * Start getting the various system monitoring solutions tied into the OSInterface --- .../core/libLumina/obsolete/RootWindow-mgmt.cpp | 95 ------------------- .../defaults/desktop/panels.conf | 21 +++++ .../core/lumina-desktop-unified/lumina-desktop.pro | 1 + .../src-desktop/src-cpp/NativeWindowObject.cpp | 19 +++- .../src-desktop/src-cpp/NativeWindowObject.h | 3 +- .../src-events/NativeWindowSystem.cpp | 6 +- .../src-events/NativeWindowSystem.h | 6 ++ .../src-events/Window-mgmt.cpp | 105 +++++++++++++++++++++ .../lumina-desktop-unified/src-events/events.pri | 3 +- src-qt5/src-cpp/framework-OSInterface-template.cpp | 73 +++----------- src-qt5/src-cpp/framework-OSInterface.h | 21 ++++- src-qt5/src-cpp/framework-OSInterface_private.cpp | 92 +++++++++++++++++- 12 files changed, 276 insertions(+), 169 deletions(-) delete mode 100644 src-qt5/core/libLumina/obsolete/RootWindow-mgmt.cpp create mode 100644 src-qt5/core/lumina-desktop-unified/defaults/desktop/panels.conf create mode 100644 src-qt5/core/lumina-desktop-unified/src-events/Window-mgmt.cpp (limited to 'src-qt5') diff --git a/src-qt5/core/libLumina/obsolete/RootWindow-mgmt.cpp b/src-qt5/core/libLumina/obsolete/RootWindow-mgmt.cpp deleted file mode 100644 index 24ea639b..00000000 --- a/src-qt5/core/libLumina/obsolete/RootWindow-mgmt.cpp +++ /dev/null @@ -1,95 +0,0 @@ -//=========================================== -// Lumina-DE source code -// Copyright (c) 2016, Ken Moore -// Available under the 3-clause BSD license -// See the LICENSE file for full details -//=========================================== -#include "RootWindow.h" - -//Primary/private function -void RootWindow::arrangeWindows(RootSubWindow *primary, QString type, bool primaryonly){ - if(type.isEmpty()){ type = "center"; } - if(primary==0){ - //Get the currently active window and treat that as the primary - for(int i=0; inativeWindow()->property(NativeWindow::Active).toBool()){ primary = WINDOWS[i]; } - } - if(primary==0 && !WINDOWS.isEmpty()){ primary = WINDOWS[0]; } //just use the first one in the list - } - //Now get the current screen that the mouse cursor is over (and valid area) - QScreen *screen = screenUnderMouse(); - QRect desktopArea = screen->availableGeometry(); - //qDebug() << "Arrange Windows:" << primary->geometry() << type << primaryonly << desktopArea; - //Now start filtering out all the windows that need to be ignored - int wkspace = primary->nativeWindow()->property(NativeWindow::Workspace).toInt(); - QList winlist = WINDOWS; - for(int i=0; inativeWindow()->property(NativeWindow::Workspace).toInt()!=wkspace - || !winlist[i]->nativeWindow()->property(NativeWindow::Visible).toBool() - || desktopArea.intersected(winlist[i]->geometry()).isNull() ){ - //window is outside of the desired area or invisible - ignore it - winlist.removeAt(i); - i--; - } - } - if(!winlist.contains(primary)){ winlist << primary; } //could be doing this on a window right before it is shown - else if(primaryonly){ winlist.removeAll(primary); winlist << primary; } //move primary window to last - //QRegion used; - for(int i=0; igeometry(); - //verify that the window is contained by the desktop area - if(geom.width()>desktopArea.width()){ geom.setWidth(desktopArea.width()); } - if(geom.height()>desktopArea.height()){ geom.setHeight(desktopArea.height()); } - //Now apply the proper placement routine - if(type=="center"){ - QPoint ct = desktopArea.center(); - winlist[i]->setGeometry( ct.x()-(geom.width()/2), ct.y()-(geom.height()/2), geom.width(), geom.height()); - }else if(type=="snap"){ - - }else if(type=="single_max"){ - winlist[i]->setGeometry( desktopArea.x(), desktopArea.y(), desktopArea.width(), desktopArea.height()); - }else if(type=="under-mouse"){ - QPoint ct = QCursor::pos(); - geom = QRect(ct.x()-(geom.width()/2), ct.y()-(geom.height()/2), geom.width(), geom.height() ); - //Now verify that the top of the window is still contained within the desktop area - if(geom.y() < desktopArea.y() ){ geom.moveTop(desktopArea.y()); } - winlist[i]->setGeometry(geom); - - } - //qDebug() << " - New Geometry:" << winlist[i]->geometry(); - } //end loop over winlist -} - -// ================ -// Public slots for starting the arrangement routine(s) above -// ================ -void RootWindow::ArrangeWindows(WId primary, QString type){ - RootSubWindow* win = windowForId(primary); - if(type.isEmpty()){ type = "center"; } //grab the default arrangement format - arrangeWindows(win, type); -} - -void RootWindow::TileWindows(WId primary, QString type){ - RootSubWindow* win = windowForId(primary); - if(type.isEmpty()){ type = "single_max"; } //grab the default arrangement format for tiling - arrangeWindows(win, type); -} - -void RootWindow::CheckWindowPosition(WId id, bool newwindow){ - //used after a "drop" to validate/snap/re-arrange window(s) as needed - // if "newwindow" is true, then this is the first-placement routine for a window before it initially appears - RootSubWindow* win = windowForId(id); - if(win==0){ return; } //invalid window - QRect geom = win->nativeWindow()->geometry(); - bool changed = false; - //Make sure it is on the screen (quick check) - if(geom.x() < 0){ changed = true; geom.moveLeft(0); } - if(geom.y() < 0){ changed = true; geom.moveTop(0); } - if(geom.width() < 20){ changed = true; geom.setWidth(100); } - if(geom.height() < 20){ changed = true; geom.setHeight(100); } - if(changed){ win->setGeometry(geom); } - //Now run it through the window arrangement routine - arrangeWindows(win, newwindow ?"center" : "snap", true); -} diff --git a/src-qt5/core/lumina-desktop-unified/defaults/desktop/panels.conf b/src-qt5/core/lumina-desktop-unified/defaults/desktop/panels.conf new file mode 100644 index 00000000..07cf4635 --- /dev/null +++ b/src-qt5/core/lumina-desktop-unified/defaults/desktop/panels.conf @@ -0,0 +1,21 @@ +[General] + +[templates] +windows/anchor="bottom" +windows/align="center" +windows/length_percent=100 +windows/plugins="" +windows/background="rgba(0,0,0,120)" + +[default] +active_ids="initial" + +[session] + +[initial] +anchor="bottom" +align="center" +length_percent=100 +width_percent=2.1 +plugins="" +background="rgba(0,0,0,120)" diff --git a/src-qt5/core/lumina-desktop-unified/lumina-desktop.pro b/src-qt5/core/lumina-desktop-unified/lumina-desktop.pro index f28b96c2..96d84a71 100644 --- a/src-qt5/core/lumina-desktop-unified/lumina-desktop.pro +++ b/src-qt5/core/lumina-desktop-unified/lumina-desktop.pro @@ -24,6 +24,7 @@ include(../libLumina/ExternalProcess.pri) include(../libLumina/XDGMime.pri) include(../../src-cpp/plugins-base.pri) +include(../../src-cpp/framework-OSInterface.pri) #include all the main individual source groups include(src-events/events.pri) diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/NativeWindowObject.cpp b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/NativeWindowObject.cpp index dae4676c..9bb78dd0 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/NativeWindowObject.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/NativeWindowObject.cpp @@ -130,6 +130,10 @@ QRect NativeWindowObject::geometry(){ return geom; } +void NativeWindowObject::setGeometryNow(QRect geom){ + updateGeometry(geom.x(), geom.y(), geom.width(), geom.height(), true); +} + // QML ACCESS FUNCTIONS (shortcuts for particular properties in a format QML can use) QString NativeWindowObject::winImage(){ //Need to alternate something on the end to ensure that QML knows to fetch the new image (non-cached only) @@ -252,16 +256,21 @@ QRect NativeWindowObject::imageGeometry(){ return geom; } -void NativeWindowObject::updateGeometry(int x, int y, int width, int height){ +void NativeWindowObject::updateGeometry(int x, int y, int width, int height, bool now){ // Full frame+window geometry - go ahead and pull it apart and only update the interior window geom QList fgeom = this->property(NativeWindowObject::FrameExtents).value >(); if(fgeom.isEmpty()){ fgeom << 0<<0<<0<<0; } //just in case (left/right/top/bottom) QPoint pos(x+fgeom[0], y+fgeom[2]); QSize sz(width-fgeom[0]-fgeom[1], height-fgeom[2]-fgeom[3]); - newgeom = QRect(pos, sz); - //qDebug() << "Update Geometry:" << fgeom << QRect(x,y,width,height) << pos << sz; - //requestProperties(QList() << NativeWindowObject::GlobalPos << NativeWindowObject::Size, QList() << pos << sz); - if(!geomTimer->isActive()){ geomTimer->start(); } + if(!now){ + newgeom = QRect(pos, sz); + //qDebug() << "Update Geometry:" << fgeom << QRect(x,y,width,height) << pos << sz; + //requestProperties(QList() << NativeWindowObject::GlobalPos << NativeWindowObject::Size, QList() << pos << sz); + if(!geomTimer->isActive()){ geomTimer->start(); } + }else{ + requestProperties(QList() << NativeWindowObject::GlobalPos << NativeWindowObject::Size , QList() << pos << sz ); + setProperties(QList() << NativeWindowObject::GlobalPos << NativeWindowObject::Size , QList() << pos << sz ); + } } // ==== PUBLIC SLOTS === diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/NativeWindowObject.h b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/NativeWindowObject.h index 332fe896..6a63813e 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/NativeWindowObject.h +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/NativeWindowObject.h @@ -92,6 +92,7 @@ public: void requestProperties(QList, QList, bool force = false); Q_INVOKABLE QRect geometry(); //this returns the "full" geometry of the window (window + frame) + void setGeometryNow(QRect geom); // QML ACCESS FUNCTIONS (shortcuts for particular properties in a format QML can use) Q_INVOKABLE QString winImage(); @@ -113,7 +114,7 @@ public: //QML Geometry reporting Q_INVOKABLE QRect frameGeometry(); Q_INVOKABLE QRect imageGeometry(); - Q_INVOKABLE void updateGeometry(int x, int y, int width, int height); //For QML to change the current window position + Q_INVOKABLE void updateGeometry(int x, int y, int width, int height, bool now = false); //For QML to change the current window position public slots: Q_INVOKABLE void toggleVisibility(); diff --git a/src-qt5/core/lumina-desktop-unified/src-events/NativeWindowSystem.cpp b/src-qt5/core/lumina-desktop-unified/src-events/NativeWindowSystem.cpp index bd6d0179..063c1337 100644 --- a/src-qt5/core/lumina-desktop-unified/src-events/NativeWindowSystem.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-events/NativeWindowSystem.cpp @@ -784,15 +784,19 @@ void NativeWindowSystem::NewWindowDetected(WId id){ registerClientEvents(win->id()); NWindows << win; UpdateWindowProperties(win, NativeWindowObject::allProperties()); - win->setProperty(NativeWindowObject::FrameExtents, QVariant::fromValue >( QList() << 5 << 5 << 30 << 5 )); + if(win->showWindowFrame()){ + win->setProperty(NativeWindowObject::FrameExtents, QVariant::fromValue >( QList() << 5 << 5 << 30 << 5 )); + } qDebug() << "New Window [& associated ID's]:" << win->id() << win->property(NativeWindowObject::Name).toString(); SetupNewWindow(win); + CheckWindowPosition(id, true); //first time placement //Now setup the connections with this window connect(win, SIGNAL(RequestClose(WId)), this, SLOT(RequestClose(WId)) ); connect(win, SIGNAL(RequestKill(WId)), this, SLOT(RequestKill(WId)) ); connect(win, SIGNAL(RequestPing(WId)), this, SLOT(RequestPing(WId)) ); connect(win, SIGNAL(RequestReparent(WId, WId, QPoint)), this, SLOT(RequestReparent(WId, WId, QPoint)) ); connect(win, SIGNAL(RequestPropertiesChange(WId, QList, QList)), this, SLOT(RequestPropertiesChange(WId, QList, QList)) ); + connect(win, SIGNAL(VerifyNewGeometry(WId)), this, SLOT(CheckWindowPosition(WId)) ); xcb_map_window(QX11Info::connection(), win->id()); emit NewWindowAvailable(win); } diff --git a/src-qt5/core/lumina-desktop-unified/src-events/NativeWindowSystem.h b/src-qt5/core/lumina-desktop-unified/src-events/NativeWindowSystem.h index 24128f32..5810fc36 100644 --- a/src-qt5/core/lumina-desktop-unified/src-events/NativeWindowSystem.h +++ b/src-qt5/core/lumina-desktop-unified/src-events/NativeWindowSystem.h @@ -129,6 +129,12 @@ private slots: void RequestPing(WId); void RequestReparent(WId, WId, QPoint); //client, parent, relative origin point in parent + //Window-mgmt functions (see Window-mgmt.cpp for details) + void ArrangeWindows(WId primary, QString type); + void TileWindows(WId primary, QString type); + void CheckWindowPosition(WId id, bool newwindow = false); + void arrangeWindows(NativeWindowObject *primary, QString type, bool primaryonly = false); + signals: void NewWindowAvailable(NativeWindowObject*); void WindowClosed(); diff --git a/src-qt5/core/lumina-desktop-unified/src-events/Window-mgmt.cpp b/src-qt5/core/lumina-desktop-unified/src-events/Window-mgmt.cpp new file mode 100644 index 00000000..0b45c208 --- /dev/null +++ b/src-qt5/core/lumina-desktop-unified/src-events/Window-mgmt.cpp @@ -0,0 +1,105 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2016, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "NativeWindowSystem.h" +inline QScreen* screenUnderMouse(){ + QPoint pos = QCursor::pos(); + QList scrns = QGuiApplication::screens(); + for(int i=0; igeometry().contains(pos)){ return scrns[i]; } + } + return 0; +} + + +//Primary/private function +void NativeWindowSystem::arrangeWindows(NativeWindowObject *primary, QString type, bool primaryonly){ + if(type.isEmpty()){ type = "center"; } + if(primary==0){ + //Get the currently active window and treat that as the primary + for(int i=0; iproperty(NativeWindowObject::Active).toBool()){ primary = NWindows[i]; } + } + if(primary==0 && !NWindows.isEmpty()){ primary = NWindows[0]; } //just use the first one in the list + } + //Now get the current screen that the mouse cursor is over (and valid area) + QScreen *screen = screenUnderMouse(); + if(screen==0){ return; } //should never happen (theoretically) + QRect desktopArea = screen->availableGeometry(); + //qDebug() << "Arrange Windows:" << primary->geometry() << type << primaryonly << desktopArea; + //Now start filtering out all the windows that need to be ignored + int wkspace = primary->property(NativeWindowObject::Workspace).toInt(); + QList winlist = NWindows; + for(int i=0; iproperty(NativeWindowObject::Workspace).toInt()!=wkspace + || !winlist[i]->property(NativeWindowObject::Visible).toBool() + || desktopArea.intersected(winlist[i]->geometry()).isNull() ){ + //window is outside of the desired area or invisible - ignore it + winlist.removeAt(i); + i--; + } + } + if(!winlist.contains(primary)){ winlist << primary; } //could be doing this on a window right before it is shown + else if(primaryonly){ winlist.removeAll(primary); winlist << primary; } //move primary window to last + //QRegion used; + for(int i=0; igeometry(); + //verify that the window is contained by the desktop area + if(geom.width()>desktopArea.width()){ geom.setWidth(desktopArea.width()); } + if(geom.height()>desktopArea.height()){ geom.setHeight(desktopArea.height()); } + //Now apply the proper placement routine + if(type=="center"){ + QPoint ct = desktopArea.center(); + winlist[i]->setGeometryNow( QRect( ct.x()-(geom.width()/2), ct.y()-(geom.height()/2), geom.width(), geom.height()) ); + }else if(type=="snap"){ + + }else if(type=="single_max"){ + winlist[i]->setGeometryNow( QRect( desktopArea.x(), desktopArea.y(), desktopArea.width(), desktopArea.height()) ); + }else if(type=="under-mouse"){ + QPoint ct = QCursor::pos(); + geom = QRect(ct.x()-(geom.width()/2), ct.y()-(geom.height()/2), geom.width(), geom.height() ); + //Now verify that the top of the window is still contained within the desktop area + if(geom.y() < desktopArea.y() ){ geom.moveTop(desktopArea.y()); } + winlist[i]->setGeometryNow(geom); + + } + //qDebug() << " - New Geometry:" << winlist[i]->geometry(); + } //end loop over winlist +} + +// ================ +// Public slots for starting the arrangement routine(s) above +// ================ +void NativeWindowSystem::ArrangeWindows(WId primary, QString type){ + NativeWindowObject* win = findWindow(primary); + if(type.isEmpty()){ type = "center"; } //grab the default arrangement format + arrangeWindows(win, type); +} + +void NativeWindowSystem::TileWindows(WId primary, QString type){ + NativeWindowObject* win = findWindow(primary); + if(type.isEmpty()){ type = "single_max"; } //grab the default arrangement format for tiling + arrangeWindows(win, type); +} + +void NativeWindowSystem::CheckWindowPosition(WId id, bool newwindow){ + //used after a "drop" to validate/snap/re-arrange window(s) as needed + // if "newwindow" is true, then this is the first-placement routine for a window before it initially appears + NativeWindowObject* win = findWindow(id); + if(win==0){ return; } //invalid window + QRect geom = win->geometry(); + bool changed = false; + //Make sure it is on the screen (quick check) + if(geom.x() < 0){ changed = true; geom.moveLeft(0); } + if(geom.y() < 0){ changed = true; geom.moveTop(0); } + if(geom.width() < 20){ changed = true; geom.setWidth(100); } + if(geom.height() < 20){ changed = true; geom.setHeight(100); } + if(changed){ win->setGeometryNow(geom); } + //Now run it through the window arrangement routine + arrangeWindows(win, newwindow ?"center" : "snap", true); +} diff --git a/src-qt5/core/lumina-desktop-unified/src-events/events.pri b/src-qt5/core/lumina-desktop-unified/src-events/events.pri index 3f89fdf2..3f586e8b 100644 --- a/src-qt5/core/lumina-desktop-unified/src-events/events.pri +++ b/src-qt5/core/lumina-desktop-unified/src-events/events.pri @@ -5,7 +5,8 @@ LIBS *= -lc -lxcb -lxcb-ewmh -lxcb-icccm -lxcb-image -lxcb-composite -lxcb-damag SOURCES *= $${PWD}/LShortcutEvents.cpp \ $${PWD}/NativeEventFilter.cpp \ $${PWD}/NativeKeyToQt.cpp \ - $${PWD}/NativeWindowSystem.cpp + $${PWD}/NativeWindowSystem.cpp \ + $${PWD}/Window-mgmt.cpp HEADERS *= $${PWD}/LShortcutEvents.h \ diff --git a/src-qt5/src-cpp/framework-OSInterface-template.cpp b/src-qt5/src-cpp/framework-OSInterface-template.cpp index a1553857..7655acb3 100644 --- a/src-qt5/src-cpp/framework-OSInterface-template.cpp +++ b/src-qt5/src-cpp/framework-OSInterface-template.cpp @@ -11,7 +11,8 @@ //Start/stop interface watchers/notifications void OSInterface::start(){ setupMediaWatcher(); //will create/connect the filesystem watcher automatically - setupNetworkManager(); + setupNetworkManager(); //will create/connect the network monitor automatically + } void OSInterface::stop(){ @@ -35,34 +36,16 @@ int OSInterface::volume(){ return -1; } void OSInterface::setVolume(int){} // = Network Information = -bool OSInterface::networkAvailable(){ - if(INFO.contains("netaccess/available")){ return INFO.value("netaccess/available").toBool(); } - return false; -} - -QString OSInterface::networkType(){ - if(INFO.contains("netaccess/type")){ return INFO.value("netaccess/type").toString(); } //"wifi", "wired", or "cell" - return ""; -} - QString OSInterface::networkTypeFromDeviceName(QString name){ //Return options: wifi, wired, cell, cell-2G, cell-3G, cell-4G return ""; } -float OSInterface::networkStrength(){ return -1; } //percentage. ("wired" type should always be 100%) - -QString OSInterface::networkHostname(){ - return QHostInfo::localHostName(); +float OSInterface::networkStrength(){ + //QString device = INFO.value("netaccess/devicename"); + return -1; //percentage. ("wired" type should always be 100%) } -QHostAddress OSInterface::networkAddress(){ - QString addr; - if(INFO.contains("netaccess/address")){ addr = INFO.value("netaccess/address").toString(); } - return QHostAddress(addr); -} -// = Network Modification = - // = Media Shortcuts = QStringList OSInterface::mediaDirectories(){ return QStringList() << "/media"; } //directory where XDG shortcuts are placed for interacting with media (local/remote) QStringList OSInterface::mediaShortcuts(){ return autoHandledMediaFiles(); } //List of currently-available XDG shortcut file paths @@ -101,55 +84,21 @@ int OSInterface::fileSystemPercentage(QString dir){ return -1; } //percentage of QString OSInterface::fileSystemCapacity(QString dir){ return QString(); } //human-readable form - total capacity // = OS-Specific Utilities = -bool OSInterface::hasControlPanel(){ return false; } QString OSInterface::controlPanelShortcut(){ return QString(); } //relative *.desktop shortcut name (Example: "some_utility.desktop") -bool OSInterface::hasAudioMixer(){ return false; } QString OSInterface::audioMixerShortcut(){ return QString(); } //relative *.desktop shortcut name (Example: "some_utility.desktop") -bool OSInterface::hasAppStore(){ return false; } QString OSInterface::appStoreShortcut(){ return QString(); } //relative *.desktop shortcut name (Example: "some_utility.desktop") +QString OSInterface::networkManagerUtility(){ return QString(); } //relative *.desktop shortcut name (Example: "some_utility.desktop") -//FileSystemWatcher slots -void OSInterface::watcherFileChanged(QString){} -void OSInterface::watcherDirChanged(QString dir){ - if(handleMediaDirChange(dir)){ return; } +//FileSystemWatcher slots (optional - re-implement only if needed/used by this OS) +void OSInterface::watcherFileChanged(QString){} //any additional parsing for files that are watched +void OSInterface::watcherDirChanged(QString dir){ //any additional parsing for watched directories + if(handleMediaDirChange(dir)){ return; } //auto-handled media directories } -//IO Device slots +//IO Device slots (optional - implement only if needed/used by this OS) void OSInterface::iodeviceReadyRead(){} void OSInterface::iodeviceAboutToClose(){} -//NetworkAccessManager slots -void OSInterface::netAccessChanged(QNetworkAccessManager::NetworkAccessibility stat){ - INFO.insert("netaccess/available", stat== QNetworkAccessManager::Accessible); - //Update all the other network status info at the same time - QNetworkConfiguration active = netman->activeConfiguration(); - //Type of connection - QString type; - switch(active.bearerTypeFamily()){ - case QNetworkConfiguration::BearerEthernet: type="wired"; break; - case QNetworkConfiguration::BearerWLAN: type="wifi"; break; - case QNetworkConfiguration::Bearer2G: type="cell-2G"; break; - case QNetworkConfiguration::Bearer3G: type="cell-3G"; break; - case QNetworkConfiguration::Bearer4G: type="cell-4G"; break; - default: type=networkTypeFromDeviceName(active.name()); //could not be auto-determined - run the OS-specific routine - } - INFO.insert("netaccess/type", type); - //qDebug() << "Detected Device Status:" << active.identifier() << type << stat; - QNetworkInterface iface = QNetworkInterface::interfaceFromName(active.name()); - //qDebug() << " - Configuration: Name:" << active.name() << active.bearerTypeName() << active.identifier(); - //qDebug() << " - Interface: MAC Address:" << iface.hardwareAddress() << "Name:" << iface.name() << iface.humanReadableName() << iface.isValid(); - QList addressList = iface.addressEntries(); - QStringList address; - //NOTE: There are often 2 addresses, IPv4 and IPv6 - for(int i=0; i&){} void OSInterface::timerUpdate(){} diff --git a/src-qt5/src-cpp/framework-OSInterface.h b/src-qt5/src-cpp/framework-OSInterface.h index f367039e..3d64483d 100644 --- a/src-qt5/src-cpp/framework-OSInterface.h +++ b/src-qt5/src-cpp/framework-OSInterface.h @@ -18,6 +18,9 @@ #include #include #include +#include +#include +#include #include #include @@ -26,6 +29,11 @@ #include #include #include +#include +#include + +//Lumina Utils class +#include class OSInterface : public QObject{ Q_OBJECT @@ -81,7 +89,9 @@ public: Q_INVOKABLE QString networkHostname(); Q_INVOKABLE QHostAddress networkAddress(); // = Network Modification = - + Q_INVOKABLE bool hasNetworkManager(); + Q_INVOKABLE QString networkManagerUtility(); //binary name or *.desktop filename (if registered on the system) + // = Media Shortcuts = Q_INVOKABLE QStringList mediaDirectories(); //directory where XDG shortcuts are placed for interacting with media (local/remote) Q_INVOKABLE QStringList mediaShortcuts(); //List of currently-available XDG shortcut file paths @@ -126,6 +136,7 @@ private slots: // ================ // SEMI-VIRTUAL FUNCTIONS - NEED TO BE DEFINED IN THE OS-SPECIFIC FILES // ================ + //FileSystemWatcher slots void watcherFileChanged(QString); void watcherDirChanged(QString); @@ -173,6 +184,9 @@ private: void connectNetman(); //setup the internal connections *only* void connectTimer(); //setup the internal connections *only* + //Internal simplification routines + bool verifyAppOrBin(QString chk); + // External Media Management (if system uses *.desktop shortcuts only) void setupMediaWatcher(); bool handleMediaDirChange(QString dir); //returns true if directory was handled @@ -180,6 +194,11 @@ private: // Qt-based NetworkAccessManager usage void setupNetworkManager(); + //void setupBatteryMonitor(int update_ms); + //void setupUpdateMonitor(int update_ms); + //void setupBrightnessMonitor(int update_ms); + //void setupVolumeMonitor(int update_ms); + //void public: OSInterface(QObject *parent = 0); diff --git a/src-qt5/src-cpp/framework-OSInterface_private.cpp b/src-qt5/src-cpp/framework-OSInterface_private.cpp index d15d9be8..709c54d4 100644 --- a/src-qt5/src-cpp/framework-OSInterface_private.cpp +++ b/src-qt5/src-cpp/framework-OSInterface_private.cpp @@ -7,9 +7,6 @@ // Internal, OS-agnostic functionality for managing the object itself //=========================================== #include -#include -#include -#include OSInterface::OSInterface(QObject *parent) : QObject(parent){ watcher = 0; @@ -63,6 +60,36 @@ void OSInterface::connectTimer(){ connect(timer, SIGNAL(timeout()), this, SLOT(timerUpdate()) ); } +bool OSInterface::verifyAppOrBin(QString chk){ + bool valid = !chk.isEmpty(); + if(valid && chk.endsWith(".desktop")){ + chk = LUtils::AppToAbsolute(chk); + valid = QFile::exists(chk); + }else if(valid){ + valid = LUtils::isValidBinary(chk); + } + return valid; +} + +// =========================== +// OS SPECIFIC EXISTANCE CHECKS +// =========================== +bool OSInterface::hasControlPanel(){ + return verifyAppOrBin(controlPanelShortcut()); +} + +bool OSInterface::hasAudioMixer(){ + return verifyAppOrBin(audioMixerShortcut()); +} + +bool OSInterface::hasAppStore(){ + return verifyAppOrBin(appStoreShortcut()); +} + +// ======================== +// MEDIA DIRECTORIES +// ======================== + // External Media Management (if system uses *.desktop shortcuts) void OSInterface::setupMediaWatcher(){ //Create/connect the watcher if needed @@ -99,6 +126,9 @@ QStringList OSInterface::autoHandledMediaFiles(){ return files; } +// ============================= +// NETWORK INTERFACE FUNCTIONS +// ============================= // Qt-based NetworkAccessManager usage void OSInterface::setupNetworkManager(){ if(netman==0){ @@ -108,3 +138,59 @@ void OSInterface::setupNetworkManager(){ //Load the initial state of the network accessibility netAccessChanged(netman->networkAccessible()); } + +bool OSInterface::networkAvailable(){ + if(INFO.contains("netaccess/available")){ return INFO.value("netaccess/available").toBool(); } + return false; +} + +QString OSInterface::networkType(){ + if(INFO.contains("netaccess/type")){ return INFO.value("netaccess/type").toString(); } //"wifi", "wired", or "cell" + return ""; +} + +QString OSInterface::networkHostname(){ + return QHostInfo::localHostName(); +} + +QHostAddress OSInterface::networkAddress(){ + QString addr; + if(INFO.contains("netaccess/address")){ addr = INFO.value("netaccess/address").toString(); } + return QHostAddress(addr); +} + +bool OSInterface::hasNetworkManager(){ + return verifyAppOrBin(networkManagerUtility()); +} + +//NetworkAccessManager slots +void OSInterface::netAccessChanged(QNetworkAccessManager::NetworkAccessibility stat){ + INFO.insert("netaccess/available", stat== QNetworkAccessManager::Accessible); + //Update all the other network status info at the same time + QNetworkConfiguration active = netman->activeConfiguration(); + //Type of connection + QString type; + switch(active.bearerTypeFamily()){ + case QNetworkConfiguration::BearerEthernet: type="wired"; break; + case QNetworkConfiguration::BearerWLAN: type="wifi"; break; + case QNetworkConfiguration::Bearer2G: type="cell-2G"; break; + case QNetworkConfiguration::Bearer3G: type="cell-3G"; break; + case QNetworkConfiguration::Bearer4G: type="cell-4G"; break; + default: type=networkTypeFromDeviceName(active.name()); //could not be auto-determined - run the OS-specific routine + } + INFO.insert("netaccess/type", type); + //qDebug() << "Detected Device Status:" << active.identifier() << type << stat; + QNetworkInterface iface = QNetworkInterface::interfaceFromName(active.name()); + //qDebug() << " - Configuration: Name:" << active.name() << active.bearerTypeName() << active.identifier(); + //qDebug() << " - Interface: MAC Address:" << iface.hardwareAddress() << "Name:" << iface.name() << iface.humanReadableName() << iface.isValid(); + QList addressList = iface.addressEntries(); + QStringList address; + //NOTE: There are often 2 addresses, IPv4 and IPv6 + for(int i=0; i Date: Sat, 13 Jan 2018 17:32:25 -0800 Subject: Another large checkpoint on the OSInterface framework for Lumina 2. --- src-qt5/src-cpp/framework-OSInterface-template.cpp | 29 ++-- src-qt5/src-cpp/framework-OSInterface.h | 56 ++++++-- src-qt5/src-cpp/framework-OSInterface_private.cpp | 153 ++++++++++++++++++++- 3 files changed, 204 insertions(+), 34 deletions(-) (limited to 'src-qt5') diff --git a/src-qt5/src-cpp/framework-OSInterface-template.cpp b/src-qt5/src-cpp/framework-OSInterface-template.cpp index 7655acb3..7921511f 100644 --- a/src-qt5/src-cpp/framework-OSInterface-template.cpp +++ b/src-qt5/src-cpp/framework-OSInterface-template.cpp @@ -5,24 +5,6 @@ // See the LICENSE file for full details //=========================================== #include -#include -#include - -//Start/stop interface watchers/notifications -void OSInterface::start(){ - setupMediaWatcher(); //will create/connect the filesystem watcher automatically - setupNetworkManager(); //will create/connect the network monitor automatically - -} - -void OSInterface::stop(){ - if(isRunning()){ - watcher->deleteLater(); - watcher = 0; - } -} - -bool OSInterface::isRunning(){ return (watcher!=0); } //status of the object - whether it has been started yet // = Battery = bool OSInterface::batteryAvailable(){ return false; } @@ -31,7 +13,7 @@ bool OSInterface::batteryCharging(){ return false; } double OSInterface::batterySecondsLeft(){ return -1; } // = Volume = -bool OSInterface::volumeAvailable(){ return false; } +bool OSInterface::volumeSupported(){ return false; } int OSInterface::volume(){ return -1; } void OSInterface::setVolume(int){} @@ -51,6 +33,7 @@ QStringList OSInterface::mediaDirectories(){ return QStringList() << "/media"; } QStringList OSInterface::mediaShortcuts(){ return autoHandledMediaFiles(); } //List of currently-available XDG shortcut file paths // = Updates = +bool OSInterface::updatesSupported(){ return false; } bool OSInterface::updatesAvailable(){ return false; } QString OSInterface::updateDetails(){ return QString(); } //Information about any available updates bool OSInterface::updatesRunning(){ return false; } @@ -59,6 +42,7 @@ bool OSInterface::updatesFinished(){ return false; } QString OSInterface::updateResults(){ return QString(); } //Information about any finished update void OSInterface::startUpdates(){} bool OSInterface::updateOnlyOnReboot(){ return false; } //Should the startUpdates function be called only when rebooting the system? +bool OSInterface::updateCausesReboot(){ return false; } QDateTime OSInterface::lastUpdate(){ return QDateTime(); } //The date/time of the previous updates QString OSInterface::lastUpdateResults(){ return QString(); } //Information about the previously-finished update @@ -71,15 +55,21 @@ bool OSInterface::canSuspend(){ return false; } void OSInterface::startSuspend(){} // = Screen Brightness = +bool OSInterface::brightnessSupported(){ return false; } int OSInterface::brightness(){ return -1; } //percentage: 0-100 with -1 for errors void OSInterface::setBrightness(int){} // = System Status Monitoring +bool OSInterface::cpuSupported(){ return false; } QList OSInterface::cpuPercentage(){ return QList(); } // (one per CPU) percentage: 0-100 with empty list for errors QStringList OSInterface::cpuTemperatures(){ return QStringList(); } // (one per CPU) Temperature of CPU ("50C" for example) + +bool OSInterface::memorySupported(){ return false; } int OSInterface::memoryUsedPercentage(){ return -1; } //percentage: 0-100 with -1 for errors QString OSInterface::memoryTotal(){ return QString(); } //human-readable form - does not tend to change within a session QStringList OSInterface::diskIO(){ return QStringList(); } //Returns list of current read/write stats for each device + +bool OSInterface::diskSupported(){ return false; } int OSInterface::fileSystemPercentage(QString dir){ return -1; } //percentage of capacity used: 0-100 with -1 for errors QString OSInterface::fileSystemCapacity(QString dir){ return QString(); } //human-readable form - total capacity @@ -101,4 +91,3 @@ void OSInterface::iodeviceAboutToClose(){} void OSInterface::netRequestFinished(QNetworkReply*){} void OSInterface::netSslErrors(QNetworkReply*, const QList&){} -void OSInterface::timerUpdate(){} diff --git a/src-qt5/src-cpp/framework-OSInterface.h b/src-qt5/src-cpp/framework-OSInterface.h index 3d64483d..f8345bac 100644 --- a/src-qt5/src-cpp/framework-OSInterface.h +++ b/src-qt5/src-cpp/framework-OSInterface.h @@ -77,10 +77,12 @@ public: Q_INVOKABLE float batteryCharge(); Q_INVOKABLE bool batteryCharging(); Q_INVOKABLE double batterySecondsLeft(); + // = Volume = - Q_INVOKABLE bool volumeAvailable(); + Q_INVOKABLE bool volumeSupported(); Q_INVOKABLE int volume(); Q_INVOKABLE void setVolume(int); + // = Network Information = Q_INVOKABLE bool networkAvailable(); Q_INVOKABLE QString networkType(); //"wifi", "wired", "cell", "cell-2G", "cell-3G", "cell-4G" @@ -88,6 +90,7 @@ public: Q_INVOKABLE float networkStrength(); //percentage. ("wired" type should always be 100%) Q_INVOKABLE QString networkHostname(); Q_INVOKABLE QHostAddress networkAddress(); + // = Network Modification = Q_INVOKABLE bool hasNetworkManager(); Q_INVOKABLE QString networkManagerUtility(); //binary name or *.desktop filename (if registered on the system) @@ -95,7 +98,9 @@ public: // = Media Shortcuts = Q_INVOKABLE QStringList mediaDirectories(); //directory where XDG shortcuts are placed for interacting with media (local/remote) Q_INVOKABLE QStringList mediaShortcuts(); //List of currently-available XDG shortcut file paths + // = Updates = + Q_INVOKABLE bool updatesSupported(); //is thie subsystem supported for the OS? Q_INVOKABLE bool updatesAvailable(); Q_INVOKABLE QString updateDetails(); //Information about any available updates Q_INVOKABLE bool updatesRunning(); @@ -104,8 +109,10 @@ public: Q_INVOKABLE QString updateResults(); //Information about any finished update Q_INVOKABLE void startUpdates(); Q_INVOKABLE bool updateOnlyOnReboot(); //Should the startUpdates function be called only when rebooting the system? + Q_INVOKABLE bool updateCausesReboot(); //Does the update power-cycle the system? Q_INVOKABLE QDateTime lastUpdate(); //The date/time of the previous updates Q_INVOKABLE QString lastUpdateResults(); //Information about the previously-finished update + // = System Power = Q_INVOKABLE bool canReboot(); Q_INVOKABLE void startReboot(); @@ -113,17 +120,26 @@ public: Q_INVOKABLE void startShutdown(); Q_INVOKABLE bool canSuspend(); Q_INVOKABLE void startSuspend(); + // = Screen Brightness = + Q_INVOKABLE bool brightnessSupported(); //is this subsystem available for the OS? Q_INVOKABLE int brightness(); //percentage: 0-100 with -1 for errors Q_INVOKABLE void setBrightness(int); + // = System Status Monitoring + Q_INVOKABLE bool cpuSupported(); //is this subsystem available for the OS? Q_INVOKABLE QList cpuPercentage(); // (one per CPU) percentage: 0-100 with -1 for errors Q_INVOKABLE QStringList cpuTemperatures(); // (one per CPU) Temperature of CPU ("50C" for example) + + Q_INVOKABLE bool memorySupported(); //is this subsystem available for the OS? Q_INVOKABLE int memoryUsedPercentage(); //percentage: 0-100 with -1 for errors Q_INVOKABLE QString memoryTotal(); //human-readable form - does not tend to change within a session Q_INVOKABLE QStringList diskIO(); //Returns list of current read/write stats for each device + + Q_INVOKABLE bool diskSupported(); //is this subsystem available for the OS? Q_INVOKABLE int fileSystemPercentage(QString dir); //percentage of capacity used: 0-100 with -1 for errors Q_INVOKABLE QString fileSystemCapacity(QString dir); //human-readable form - total capacity + // = OS-Specific Utilities = Q_INVOKABLE bool hasControlPanel(); Q_INVOKABLE QString controlPanelShortcut(); //relative *.desktop shortcut name (Example: "some_utility.desktop") @@ -132,6 +148,9 @@ public: Q_INVOKABLE bool hasAppStore(); Q_INVOKABLE QString appStoreShortcut(); //relative *.desktop shortcut name (Example: "some_utility.desktop") + + // QML-Accessible properties/functions + private slots: // ================ // SEMI-VIRTUAL FUNCTIONS - NEED TO BE DEFINED IN THE OS-SPECIFIC FILES @@ -148,7 +167,13 @@ private slots: void netRequestFinished(QNetworkReply*); void netSslErrors(QNetworkReply*, const QList&); //Timer slots - void timerUpdate(); + void BatteryTimerUpdate(); + void UpdateTimerUpdate(); + void BrightnessTimerUpdate(); + void VolumeTimerUpdate(); + void CpuTimerUpdate(); + void MemTimerUpdate(); + void DiskTimerUpdate(); signals: void batteryChargeChanged(); @@ -164,6 +189,7 @@ signals: private: //Internal persistant data storage, OS-specific usage implementation QHash< QString, QVariant> INFO; + bool _started; // ============ // Internal possibilities for watching the system (OS-Specific usage/implementation) @@ -175,14 +201,13 @@ private: //Network Access Manager (check network connectivity, etc) QNetworkAccessManager *netman; //Timer for regular probes/updates - QTimer *timer; + QTimer *batteryTimer, *updateTimer, *brightnessTimer, *volumeTimer, *cpuTimer, *memTimer, *diskTimer; // Internal implifications for connecting the various watcher objects to their respective slots // (OS-agnostic - defined in the "OSInterface_private.cpp" file) void connectWatcher(); //setup the internal connections *only* void connectIodevice(); //setup the internal connections *only* void connectNetman(); //setup the internal connections *only* - void connectTimer(); //setup the internal connections *only* //Internal simplification routines bool verifyAppOrBin(QString chk); @@ -194,11 +219,24 @@ private: // Qt-based NetworkAccessManager usage void setupNetworkManager(); - //void setupBatteryMonitor(int update_ms); - //void setupUpdateMonitor(int update_ms); - //void setupBrightnessMonitor(int update_ms); - //void setupVolumeMonitor(int update_ms); - //void + + // Timer-based monitors + void setupBatteryMonitor(int update_ms, int delay_ms); + void setupUpdateMonitor(int update_ms, int delay_ms); + void setupBrightnessMonitor(int update_ms, int delay_ms); + void setupVolumeMonitor(int update_ms, int delay_ms); + void setupCpuMonitor(int update_ms, int delay_ms); + void setupMemoryMonitor(int update_ms, int delay_ms); + void setupDiskMonitor(int update_ms, int delay_ms); + + // Timer-based monitor update routines (NOTE: these are all run in a separate thread!!) + void syncBatteryInfo(OSInterface *os, QHash *hash, QTimer *timer); + void syncUpdateInfo(OSInterface *os, QHash *hash, QTimer *timer); + void syncBrightnessInfo(OSInterface *os, QHash *hash, QTimer *timer); + void syncVolumeInfo(OSInterface *os, QHash *hash, QTimer *timer); + void syncCpuInfo(OSInterface *os, QHash *hash, QTimer *timer); + void syncMemoryInfo(OSInterface *os, QHash *hash, QTimer *timer); + void syncDiskInfo(OSInterface *os, QHash *hash, QTimer *timer); public: OSInterface(QObject *parent = 0); diff --git a/src-qt5/src-cpp/framework-OSInterface_private.cpp b/src-qt5/src-cpp/framework-OSInterface_private.cpp index 709c54d4..d633fe9a 100644 --- a/src-qt5/src-cpp/framework-OSInterface_private.cpp +++ b/src-qt5/src-cpp/framework-OSInterface_private.cpp @@ -7,6 +7,7 @@ // Internal, OS-agnostic functionality for managing the object itself //=========================================== #include +#include OSInterface::OSInterface(QObject *parent) : QObject(parent){ watcher = 0; @@ -37,6 +38,33 @@ OSInterface* OSInterface::instance(){ return m_os_object; } +//Start/stop interface systems +void OSInterface::start(){ + if(!mediaDirectories().isEmpty()){ setupMediaWatcher(); }//will create/connect the filesystem watcher automatically + setupNetworkManager(); //will create/connect the network monitor automatically + if(batteryAvailable()){ setupBatteryMonitor(30000, 1); } //30 second updates, 1 ms init delay + if(brightnessSupported()){ setupBrightnessMonitor(60000, 1); } //1 minute updates, 1 ms init delay + if(volumeSupported()){ setupVolumeMonitor(60000, 2); } //1 minute updates, 2 ms init delay + if(updatesSupported()){ setupUpdateMonitor(12*60*60*1000, 5*60*1000); } //12-hour updates, 5 minute delay + if(cpuSupported()){ setupCpuMonitor(2000, 20); } //2 second updates, 20 ms init delay + if(memorySupported()){ setupMemoryMonitor(2000, 21); } //2 second updates, 21 ms init delay + if(diskSupported()){ setupDiskMonitor(60000, 25); } //1 minute updates, 25 ms init delay +} + +void OSInterface::stop(){ + if(watcher!=0){ watcher->deleteLater(); watcher=0; } + if(batteryTimer!=0){ batteryTimer->stop(); disconnect(batteryTimer); } + if(brightnessTimer!=0){ brightnessTimer->stop(); disconnect(brightnessTimer); } + if(volumeTimer!=0){ volumeTimer->stop(); disconnect(volumeTimer); } + if(updateTimer!=0){ updateTimer->stop(); disconnect(updateTimer); } + if(cpuTimer!=0){ cpuTimer->stop(); disconnect(cpuTimer); } + if(memTimer!=0){ memTimer->stop(); disconnect(memTimer); } + if(diskTimer!=0){ diskTimer->stop(); disconnect(diskTimer); } + if(netman!=0){ disconnect(netman); netman->deleteLater(); netman = 0; } +} + +bool OSInterface::isRunning(){ return _started; } //status of the object - whether it has been started yet + void OSInterface::connectWatcher(){ if(watcher==0){ return; } connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(watcherFileChanged(QString)) ); @@ -55,11 +83,6 @@ void OSInterface::connectNetman(){ connect(netman, SIGNAL(sslErrors(QNetworkReply*, const QList&)), this, SLOT(netSslErrors(QNetworkReply*, const QList&)) ); } -void OSInterface::connectTimer(){ - if(timer==0){ return; } - connect(timer, SIGNAL(timeout()), this, SLOT(timerUpdate()) ); -} - bool OSInterface::verifyAppOrBin(QString chk){ bool valid = !chk.isEmpty(); if(valid && chk.endsWith(".desktop")){ @@ -194,3 +217,123 @@ void OSInterface::netAccessChanged(QNetworkAccessManager::NetworkAccessibility s INFO.insert("netaccess/address", address.join(", ")); emit networkStatusChanged(); } + + +// ======================== +// TIMER-BASED MONITORS +// ======================== +//Timer slots +void OSInterface::BatteryTimerUpdate(){ + QtConcurrent::run(this, &OSInterface::syncBatteryInfo, this, &INFO, batteryTimer); +} + +void OSInterface::UpdateTimerUpdate(){ + QtConcurrent::run(this, &OSInterface::syncUpdateInfo, this, &INFO, updateTimer); +} + +void OSInterface::BrightnessTimerUpdate(){ + QtConcurrent::run(this, &OSInterface::syncBrightnessInfo, this, &INFO, brightnessTimer); +} + +void OSInterface::VolumeTimerUpdate(){ + QtConcurrent::run(this, &OSInterface::syncVolumeInfo, this, &INFO, volumeTimer); +} + +void OSInterface::CpuTimerUpdate(){ + QtConcurrent::run(this, &OSInterface::syncCpuInfo, this, &INFO, cpuTimer); +} + +void OSInterface::MemTimerUpdate(){ + QtConcurrent::run(this, &OSInterface::syncMemoryInfo, this, &INFO, memTimer); +} + +void OSInterface::DiskTimerUpdate(){ + QtConcurrent::run(this, &OSInterface::syncDiskInfo, this, &INFO, diskTimer); +} + +// Timer Setup functions +void OSInterface::setupBatteryMonitor(int update_ms, int delay_ms){ + batteryTimer = new QTimer(this); + batteryTimer->setSingleShot(true); + batteryTimer->setInterval(update_ms); + connect(batteryTimer, SIGNAL(timeout()), this, SLOT(BatteryTimerUpdate()) ); + QTimer::singleShot(delay_ms, this, SLOT(BatteryTimerUpdate()) ); +} +void OSInterface::setupUpdateMonitor(int update_ms, int delay_ms){ + updateTimer = new QTimer(this); + updateTimer->setSingleShot(true); + updateTimer->setInterval(update_ms); + connect(updateTimer, SIGNAL(timeout()), this, SLOT(UpdateTimerUpdate()) ); + QTimer::singleShot(delay_ms, this, SLOT(UpdateTimerUpdate()) ); +} +void OSInterface::setupBrightnessMonitor(int update_ms, int delay_ms){ + brightnessTimer = new QTimer(this); + brightnessTimer->setSingleShot(true); + brightnessTimer->setInterval(update_ms); + connect(brightnessTimer, SIGNAL(timeout()), this, SLOT(BrightnessTimerUpdate()) ); + QTimer::singleShot(delay_ms, this, SLOT(BrightnessTimerUpdate()) ); +} +void OSInterface::setupVolumeMonitor(int update_ms, int delay_ms){ + volumeTimer = new QTimer(this); + volumeTimer->setSingleShot(true); + volumeTimer->setInterval(update_ms); + connect(volumeTimer, SIGNAL(timeout()), this, SLOT(VolumeTimerUpdate()) ); + QTimer::singleShot(delay_ms, this, SLOT(VolumeTimerUpdate()) ); +} +void OSInterface::setupCpuMonitor(int update_ms, int delay_ms){ + cpuTimer = new QTimer(this); + cpuTimer->setSingleShot(true); + cpuTimer->setInterval(update_ms); + connect(cpuTimer, SIGNAL(timeout()), this, SLOT(CpuTimerUpdate()) ); + QTimer::singleShot(delay_ms, this, SLOT(CpuTimerUpdate()) ); +} +void OSInterface::setupMemoryMonitor(int update_ms, int delay_ms){ + memTimer = new QTimer(this); + memTimer->setSingleShot(true); + memTimer->setInterval(update_ms); + connect(memTimer, SIGNAL(timeout()), this, SLOT(MemTimerUpdate()) ); + QTimer::singleShot(delay_ms, this, SLOT(MemTimerUpdate()) ); +} +void OSInterface::setupDiskMonitor(int update_ms, int delay_ms){ + diskTimer = new QTimer(this); + diskTimer->setSingleShot(true); + diskTimer->setInterval(update_ms); + connect(diskTimer, SIGNAL(timeout()), this, SLOT(DiskTimerUpdate()) ); + QTimer::singleShot(delay_ms, this, SLOT(DiskTimerUpdate()) ); +} + +// Timer-based monitor update routines (NOTE: these are all run in a separate thread!!) +void OSInterface::syncBatteryInfo(OSInterface *os, QHash *hash, QTimer *timer){ + + QTimer::singleShot(0, timer, SLOT(start())); +} + +void OSInterface::syncUpdateInfo(OSInterface *os, QHash *hash, QTimer *timer){ + + QTimer::singleShot(0, timer, SLOT(start())); +} + +void OSInterface::syncBrightnessInfo(OSInterface *os, QHash *hash, QTimer *timer){ + + QTimer::singleShot(0, timer, SLOT(start())); +} + +void OSInterface::syncVolumeInfo(OSInterface *os, QHash *hash, QTimer *timer){ + + QTimer::singleShot(0, timer, SLOT(start())); +} + +void OSInterface::syncCpuInfo(OSInterface *os, QHash *hash, QTimer *timer){ + + QTimer::singleShot(0, timer, SLOT(start())); +} + +void OSInterface::syncMemoryInfo(OSInterface *os, QHash *hash, QTimer *timer){ + + QTimer::singleShot(0, timer, SLOT(start())); +} + +void OSInterface::syncDiskInfo(OSInterface *os, QHash *hash, QTimer *timer){ + + QTimer::singleShot(0, timer, SLOT(start())); +} -- cgit