Ver código fonte

split fancontrol-gui into main and a library

Malte Veerman 10 anos atrás
pai
commit
a22e941e7e

+ 2 - 25
fancontrol-gui/CMakeLists.txt

@@ -1,30 +1,7 @@
-set(Fancontrol-GUI_SRCS src/main.cpp
-                        src/loader.cpp
-                        src/hwmon.cpp
-                        src/sensors.cpp)
-
-set(LIBRARIES ${Qt5Widgets_LIBRARIES}
-              ${Qt5Qml_Libraries}
-              ${Qt5Quick_LIBRARIES}
-              KF5::Auth
-              KF5::ConfigCore)
-
-if(NO_SYSTEMD)
-
-    add_definitions(-DNO_SYSTEMD)
-
-else(NO_SYSTEMD)
-
-    set(Fancontrol-GUI_SRCS ${Fancontrol-GUI_SRCS}
-                            src/systemdcommunicator.cpp)
-
-    set(LIBRARIES ${LIBRARIES}
-                  Qt5::DBus)
-
-endif(NO_SYSTEMD)
+set(Fancontrol-GUI_SRCS src/main.cpp)
 
 add_executable(fancontrol-gui ${Fancontrol-GUI_SRCS} ${RESOURCES})
-target_link_libraries(fancontrol-gui ${LIBRARIES})
+target_link_libraries(fancontrol-gui LINK_PUBLIC fancontrol-gui-lib)
 set_property(TARGET fancontrol-gui PROPERTY CXX_STANDARD 11)
 
 install(TARGETS fancontrol-gui RUNTIME DESTINATION bin)

+ 2 - 2
fancontrol-gui/src/main.cpp

@@ -22,10 +22,10 @@
 #include <QQmlContext>
 #include <QQuickView>
 
-#include "loader.h"
+#include "../share/src/loader.h"
 
 #ifndef NO_SYSTEMD
-#include "systemdcommunicator.h"
+#include "../share/src/systemdcommunicator.h"
 #endif
 
 int main(int argc, char *argv[])

+ 31 - 0
share/CMakeLists.txt

@@ -1,2 +1,33 @@
+set(LIB_SRCS src/loader.cpp
+             src/hwmon.cpp
+             src/sensors.cpp)
+
+set(LIBRARIES ${Qt5Widgets_LIBRARIES}
+              ${Qt5Qml_Libraries}
+              ${Qt5Quick_LIBRARIES}
+              KF5::Auth
+              KF5::ConfigCore)
+
+if(NO_SYSTEMD)
+
+    add_definitions(-DNO_SYSTEMD)
+
+else(NO_SYSTEMD)
+
+    set(LIB_SRCS ${LIB_SRCS}
+                 src/systemdcommunicator.cpp)
+
+    set(LIBRARIES ${LIBRARIES}
+                  Qt5::DBus)
+
+endif(NO_SYSTEMD)
+
+add_definitions(-DFANCONTROL_GUI_LIBRARY)
+
+add_library(fancontrol-gui-lib ${LIB_SRCS})
+
+target_link_libraries(fancontrol-gui-lib ${LIBRARIES})
+target_include_directories (fancontrol-gui-lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
+
 install(DIRECTORY qml DESTINATION ${CMAKE_INSTALL_PREFIX}/share/fancontrol-gui)
 install(DIRECTORY javascript DESTINATION ${CMAKE_INSTALL_PREFIX}/share/fancontrol-gui)

+ 11 - 0
share/src/export.h

@@ -0,0 +1,11 @@
+#ifndef LIBRARY_H
+#define LIBRARY_H
+
+#if defined(FANCONTROL_GUI_LIBRARY)
+#  define FANCONTROL_GUI_EXPORT Q_DECL_EXPORT
+#else
+#  define FANCONTROL_GUI_EXPORT Q_DECL_IMPORT
+#endif
+
+#endif // LIBRARY_H
+

+ 0 - 0
fancontrol-gui/src/hwmon.cpp → share/src/hwmon.cpp


+ 2 - 1
fancontrol-gui/src/hwmon.h → share/src/hwmon.h

@@ -24,13 +24,14 @@
 
 #include "sensors.h"
 #include "loader.h"
+#include "export.h"
 
 class Fan;
 class PwmFan;
 class Temp;
 class Loader;
 
-class Hwmon : public QObject
+class FANCONTROL_GUI_EXPORT Hwmon : public QObject
 {
     Q_OBJECT
     Q_PROPERTY(QString name READ name CONSTANT)

+ 0 - 19
fancontrol-gui/src/loader.cpp → share/src/loader.cpp

@@ -24,11 +24,9 @@
 #include <QTextStream>
 #include <QDebug>
 
-#ifndef NO_KF5_AUTH
 #include <KF5/KAuth/kauthexecutejob.h>
 
 using namespace KAuth;
-#endif
 
 #define HWMON_PATH "/sys/class/hwmon"
 
@@ -88,14 +86,6 @@ void Loader::open(const QUrl &url)
         m_error = "Success";
         emit errorChanged();
     }
-#ifdef NO_KF5_AUTH
-    else
-    {
-        m_error = file.errorString();
-        emit errorChanged();
-        return;
-    }
-#else
     else if (file.exists())
     {
         Action action("fancontrol.gui.helper.read");
@@ -118,7 +108,6 @@ void Loader::open(const QUrl &url)
             stream.setString(&string);
         }
     }
-#endif
     m_configFile = stream.readAll();
     emit configFileChanged();
     m_configUrl = url;
@@ -293,13 +282,6 @@ void Loader::save(const QUrl &url)
         stream << m_configFile;
         qDebug() << m_configFile;
     }
-#ifdef NO_KF5_AUTH
-    else
-    {
-        m_error = file.errorString();
-        emit errorChanged();
-    }
-#else
     else
     {
         Action action("fancontrol.gui.helper.write");
@@ -316,7 +298,6 @@ void Loader::save(const QUrl &url)
             emit errorChanged();
         }
     }
-#endif
 }
 
 void Loader::createConfigFile()

+ 2 - 1
fancontrol-gui/src/loader.h → share/src/loader.h

@@ -26,10 +26,11 @@
 #include <QTimer>
 
 #include "hwmon.h"
+#include "export.h"
 
 class Hwmon;
 
-class Loader : public QObject
+class FANCONTROL_GUI_EXPORT Loader : public QObject
 {
     Q_OBJECT
     Q_PROPERTY(QUrl configUrl READ configUrl WRITE setConfigUrl NOTIFY configUrlChanged)

+ 0 - 0
fancontrol-gui/src/sensors.cpp → share/src/sensors.cpp


+ 4 - 3
fancontrol-gui/src/sensors.h → share/src/sensors.h

@@ -26,6 +26,7 @@
 #include <KSharedConfig>
 
 #include "hwmon.h"
+#include "export.h"
 
 class Hwmon;
 
@@ -64,7 +65,7 @@ protected:
 };
 
 
-class Temp : public Sensor
+class FANCONTROL_GUI_EXPORT Temp : public Sensor
 {
     Q_OBJECT
     Q_PROPERTY(QString label READ label NOTIFY labelChanged)
@@ -99,7 +100,7 @@ protected:
 };
 
 
-class Fan : public Sensor
+class FANCONTROL_GUI_EXPORT Fan : public Sensor
 {
     Q_OBJECT
     Q_PROPERTY(int rpm READ rpm NOTIFY rpmChanged)
@@ -133,7 +134,7 @@ protected:
 };
 
 
-class PwmFan : public Fan
+class FANCONTROL_GUI_EXPORT PwmFan : public Fan
 {
     Q_OBJECT
     //Q_PROPERTY(int pwm READ pwm WRITE setPwm NOTIFY pwmChanged)

+ 0 - 2
fancontrol-gui/src/systemdcommunicator.cpp → share/src/systemdcommunicator.cpp

@@ -19,11 +19,9 @@
 
 #include "systemdcommunicator.h"
 
-#ifndef NO_KF5_AUTH
 #include <KF5/KAuth/kauthexecutejob.h>
 
 using namespace KAuth;
-#endif
 
 #include <QDebug>
 #include <QVariant>

+ 5 - 3
fancontrol-gui/src/systemdcommunicator.h → share/src/systemdcommunicator.h

@@ -23,7 +23,9 @@
 #include <QObject>
 #include <QtDBus/QtDBus>
 
-class SystemdCommunicator : public QObject
+#include "export.h"
+
+class FANCONTROL_GUI_EXPORT SystemdCommunicator : public QObject
 {
     Q_OBJECT
     Q_PROPERTY(QString serviceName READ serviceName WRITE setServiceName NOTIFY serviceNameChanged)
@@ -68,7 +70,7 @@ Q_DECLARE_METATYPE(SystemdUnitFile)
 typedef QList<SystemdUnitFile> SystemdUnitFileList;
 Q_DECLARE_METATYPE(SystemdUnitFileList)
 
-QDBusArgument &operator<<(QDBusArgument &argument, const SystemdUnitFile &unitFile);
-const QDBusArgument &operator>>(const QDBusArgument &argument, SystemdUnitFile &unitFile);
+QDBusArgument &operator <<(QDBusArgument &argument, const SystemdUnitFile &unitFile);
+const QDBusArgument &operator >>(const QDBusArgument &argument, SystemdUnitFile &unitFile);
 
 #endif // SYSTEMDCOMMUNICATOR_H