OSDN Git Service

generic: make use of QHostInfo::localHostName() and QHostInfo::localDomainName()
authorIvailo Monev <xakepa10@gmail.com>
Sun, 11 Jul 2021 10:28:35 +0000 (13:28 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Sun, 11 Jul 2021 10:39:10 +0000 (13:39 +0300)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
kdm/ConfigureChecks.cmake
kdm/config-kdm.h.cmake
kdm/kfrontend/CMakeLists.txt
kdm/kfrontend/themer/kdmlabel.cpp
libs/ksysguard/processcore/processes_openbsd_p.cpp
plasma/applets/kickoff/CMakeLists.txt
plasma/applets/kickoff/ui/launcher.cpp

index 939b756..95f3869 100644 (file)
@@ -12,8 +12,6 @@ check_include_files(termios.h HAVE_TERMIOS_H)
 check_include_files(sys/sockio.h HAVE_SYS_SOCKIO_H)
 
 check_symbol_exists(sysinfo "sys/sysinfo.h" HAVE_SYSINFO)
-check_symbol_exists(systeminfo "sys/systeminfo.h" HAVE_SYS_SYSTEMINFO)
-check_symbol_exists(getdomainname   "unistd.h"    HAVE_GETDOMAINNAME)
 
 check_function_exists(initgroups HAVE_INITGROUPS)
 check_function_exists(mkstemp HAVE_MKSTEMP)
index 9d656a6..d508f59 100644 (file)
 /* Define to 1 if `sin_len' is member of `struct sockaddr_in'. */
 #cmakedefine HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
 
-/* Define if you have getdomainname */
-#cmakedefine HAVE_GETDOMAINNAME 1
-
 /* Define to 1 if you have the <termio.h> header file. */
 #cmakedefine HAVE_TERMIO_H 1
 
index 4cf6963..ae40002 100644 (file)
@@ -69,12 +69,17 @@ endif (WITH_KDM_XCONSOLE)
 macro_add_file_dependencies(kdmconfig.h ${confci})
 macro_add_file_dependencies(kdmconfig.cpp ${confci})
 add_executable(kdm_greet ${kdm_greet_SRCS})
-target_link_libraries(kdm_greet ${KDE4_KDEUI_LIBS} ${QT_QTXML_LIBRARY} ${X11_X11_LIB})
+target_link_libraries(kdm_greet
+    ${KDE4_KDEUI_LIBS}
+    ${QT_QTXML_LIBRARY}
+    ${QT_QTNETWORK_LIBRARY}
+    ${X11_X11_LIB}
+)
 if (X11_XTest_FOUND)
-  target_link_libraries(kdm_greet ${X11_XTest_LIB})
+    target_link_libraries(kdm_greet ${X11_XTest_LIB})
 endif (X11_XTest_FOUND)
 if (WITH_KDM_XCONSOLE)
-  target_link_libraries(kdm_greet ${KDE4_KPTY_LIBS})
+    target_link_libraries(kdm_greet ${KDE4_KPTY_LIBS})
 endif (WITH_KDM_XCONSOLE)
 add_dependencies(kdm_greet ConfigCi)
 
index 435d08b..d171732 100644 (file)
@@ -36,6 +36,7 @@
 #include <QHash>
 #include <QPainter>
 #include <QTimer>
+#include <QHostInfo>
 #include <QtGui/qx11info_x11.h>
 
 #include <X11/Xlib.h>
@@ -43,9 +44,6 @@
 
 #include <unistd.h>
 #include <sys/utsname.h>
-#if !defined(HAVE_GETDOMAINNAME) && defined(HAVE_SYS_SYSTEMINFO)
-# include <sys/systeminfo.h>
-#endif
 
 KdmLabel::KdmLabel(QObject *parent, const QDomNode &node)
     : KdmItem(parent, node)
@@ -313,14 +311,16 @@ KdmLabel::expandMacro(QChar chr, QStringList &ret)
         expandoMap['s'] = QString::fromLocal8Bit(uts.sysname);
         expandoMap['r'] = QString::fromLocal8Bit(uts.release);
         expandoMap['m'] = QString::fromLocal8Bit(uts.machine);
-        char buf[256];
-        buf[sizeof(buf) - 1] = '\0';
-        expandoMap['h'] = gethostname(buf, sizeof(buf) - 1) ? "localhost" : QString::fromLocal8Bit(buf);
-#ifdef HAVE_GETDOMAINNAME
-        expandoMap['o'] = getdomainname(buf, sizeof(buf) - 1) ? "localdomain" : QString::fromLocal8Bit(buf);
-#elif defined(HAVE_SYS_SYSTEMINFO)
-        expandoMap['o'] = (unsigned)sysinfo(SI_SRPC_DOMAIN, buf, sizeof(buf)) > sizeof(buf) ? "localdomain" : QString::fromLocal8Bit(buf);
-#endif
+        QString hostname = QHostInfo::localHostName();
+        if (hostname.isEmpty()) {
+            hostname = QLatin1String("localhost");
+        }
+        QString domainname = QHostInfo::localDomainName();
+        if (domainname.isEmpty()) {
+            domainname = QLatin1String("localdomain");
+        }
+        expandoMap['h'] = hostname;
+        expandoMap['o'] = domainname;
     }
     QHash<QChar, QString>::const_iterator mi = expandoMap.constFind(chr);
     if (mi != expandoMap.constEnd()) {
index 6fc238d..2e7d97c 100644 (file)
@@ -224,7 +224,7 @@ QSet<long> ProcessesLocal::getAllPids( )
 
 bool ProcessesLocal::sendSignal(long pid, int sig)
 {
-    if (:;kill((pid_t)pid, sig) == -1) {
+    if (::kill((pid_t)pid, sig) == -1) {
         // kill failed
         return false;
     }
index c8c5ef8..29c6816 100644 (file)
@@ -50,9 +50,20 @@ set(Applet_SRCS
 )
 
 kde4_add_plugin(plasma_applet_launcher ${Applet_SRCS})
-target_link_libraries(plasma_applet_launcher ${KDE4_PLASMA_LIBS} ${Kickoff_LIBS} kickoff)
-install(TARGETS plasma_applet_launcher DESTINATION ${KDE4_PLUGIN_INSTALL_DIR})
-install(FILES applet/plasma-applet-launcher.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR})
+target_link_libraries(plasma_applet_launcher
+    ${KDE4_PLASMA_LIBS}
+    ${QT_QTNETWORK_LIBRARY}
+    ${Kickoff_LIBS}
+    kickoff
+)
+install(
+    TARGETS plasma_applet_launcher
+    DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}
+)
+install(
+    FILES applet/plasma-applet-launcher.desktop
+    DESTINATION ${KDE4_SERVICES_INSTALL_DIR}
+)
 
 #######################################################################################
 # Kickoff Simple KMenu Plasma Applet
@@ -63,9 +74,20 @@ set(SimpleApplet_SRCS
     simpleapplet/simpleapplet.cpp
 )
 kde4_add_plugin(plasma_applet_simplelauncher ${SimpleApplet_SRCS})
-target_link_libraries(plasma_applet_simplelauncher ${KDE4_KCMUTILS_LIBS} ${KDE4_PLASMA_LIBS} ${Kickoff_LIBS} kickoff)
-install(TARGETS plasma_applet_simplelauncher DESTINATION ${KDE4_PLUGIN_INSTALL_DIR})
-install(FILES simpleapplet/plasma-applet-simplelauncher.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR})
+target_link_libraries(plasma_applet_simplelauncher
+    ${KDE4_KCMUTILS_LIBS}
+    ${KDE4_PLASMA_LIBS}
+    ${Kickoff_LIBS}
+    kickoff
+)
+install(
+    TARGETS plasma_applet_simplelauncher
+    DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}
+)
+install(
+    FILES simpleapplet/plasma-applet-simplelauncher.desktop
+    DESTINATION ${KDE4_SERVICES_INSTALL_DIR}
+)
 
 # Kickoff Standalone Test Application
 #IF (CMAKE_BUILD_TYPE MATCHES Debug)
index 56c17da..65873f6 100644 (file)
@@ -21,9 +21,6 @@
 
 #include "ui/launcher.h"
 
-// System
-#include <unistd.h>
-
 // Qt
 #include <QApplication>
 #include <QtGui/qevent.h>
@@ -34,6 +31,7 @@
 #include <QTabBar>
 #include <QToolButton>
 #include <QVBoxLayout>
+#include <QHostInfo>
 
 // KDE
 #include <KDebug>
@@ -552,11 +550,7 @@ void Launcher::init()
     // Add status information footer
     d->footer = new QWidget;
 
-    char hostname[256];
-    hostname[0] = '\0';
-    if (!gethostname(hostname, sizeof(hostname))) {
-        hostname[sizeof(hostname)-1] = '\0';
-    }
+    const QString hostname = QHostInfo::localHostName();
     KUser user;
     QString fullName = user.property(KUser::FullName).toString();
     QString labelText;