Add an initial Qt port.
authorRoy Marples <roy@marples.name>
Sat, 16 Aug 2014 14:52:23 +0000 (14:52 +0000)
committerRoy Marples <roy@marples.name>
Sat, 16 Aug 2014 14:52:23 +0000 (14:52 +0000)
SSID selection and preferenecs still need to be implemented.

14 files changed:
configure
src/dhcpcd-qt/Makefile [new file with mode: 0644]
src/dhcpcd-qt/dhcpcd-about.cpp [new file with mode: 0644]
src/dhcpcd-qt/dhcpcd-about.h [new file with mode: 0644]
src/dhcpcd-qt/dhcpcd-preferences.cpp [new file with mode: 0644]
src/dhcpcd-qt/dhcpcd-preferences.h [new file with mode: 0644]
src/dhcpcd-qt/dhcpcd-qt.cpp [new file with mode: 0644]
src/dhcpcd-qt/dhcpcd-qt.h [new file with mode: 0644]
src/dhcpcd-qt/dhcpcd-qt.pro [new file with mode: 0644]
src/dhcpcd-qt/dhcpcd-ssidmenu.cpp [new file with mode: 0644]
src/dhcpcd-qt/dhcpcd-ssidmenu.h [new file with mode: 0644]
src/dhcpcd-qt/dhcpcd-wi.cpp [new file with mode: 0644]
src/dhcpcd-qt/dhcpcd-wi.h [new file with mode: 0644]
src/dhcpcd-qt/main.cpp [new file with mode: 0644]

index 29f6fba052c51ed1f59bacacd24dadde7f09b58a..80c2b4f88273567a12e574f46b26a4d171bc30c3 100755 (executable)
--- a/configure
+++ b/configure
@@ -257,8 +257,9 @@ EOF
        rm -f _strlcpy.c _strlcpy
 fi
 if [ "$STRLCPY" = no ]; then
-       echo "#define strlcpy(dst, src, n) snprintf(dst, n, \"%s\", src)" \
-       >>$CONFIG_H
+       echo "#define strlcpy(dst, src, n) " \
+           "((size_t)snprintf(dst, n, \"%s\", src))" \
+           >>$CONFIG_H
 fi
 
 if [ -z "$LIBDIR" ]; then
@@ -301,7 +302,7 @@ elif [ -n "$WITH_GTK" -a "$WITH_GTK" != no ]; then
                exit 1
        fi
 fi
-
+       
 if [ -n "$WITH_GTK" ]; then
        PKG="$WITH_GTK"
        if [ "$NOTIFY" = yes ]; then
@@ -319,6 +320,22 @@ if [ -n "$WITH_GTK" ]; then
        UI="$UI${UI:+ }dhcpcd-gtk"
 fi
 
+DHCPCD_QT=false
+if [ "WITH_QT" = yes -o -z "$WITH_QT" ]; then
+       if type qmake >/dev/null 2>&1; then
+               UI="$UI${UI+ }dhcpcd-qt"
+               DHCPCD_QT=true
+       fi
+elif [ -n "$WITH_QT" -a "$WITH_QT" != no ]; then
+       if type qmake >/dev/null 2>&1; then
+               UI="$UI${UI+ }dhcpcd-qt"
+               DHCPCD_QT=true
+       else
+               echo "$0: no suitable QT library has been found" >&2
+               exit 1
+       fi
+fi
+
 if [ -z "$UI" ]; then
        echo "$0: no UI is available, not building." >&2
        exit 1
@@ -335,3 +352,10 @@ echo "   UI =                      $UI"
 echo
 
 echo "MKDIR=           \${TOPDIR}/mk" >>$CONFIG_MK
+
+if $DHCPCD_QT; then
+       if ! (cd src/dhcpcd-qt; qmake dhcpcd-qt.pro); then
+               echo "$0: failed to configure dhcpcd-qt" >&2
+               exit 1
+       fi
+fi
diff --git a/src/dhcpcd-qt/Makefile b/src/dhcpcd-qt/Makefile
new file mode 100644 (file)
index 0000000..6b14e35
--- /dev/null
@@ -0,0 +1,299 @@
+#############################################################################
+# Makefile for building: dhcpcd-qt
+# Generated by qmake (2.01a) (Qt 4.8.5) on: Sat Aug 16 15:48:57 2014
+# Project:  dhcpcd-qt.pro
+# Template: app
+# Command: /usr/bin/qmake -o Makefile dhcpcd-qt.pro
+#############################################################################
+
+####### Compiler, tools and options
+
+CC            = gcc
+CXX           = g++
+DEFINES       = -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
+CFLAGS        = -pipe -g -D_REENTRANT -Wall -W $(DEFINES)
+CXXFLAGS      = -pipe -std=c++11 -g -D_REENTRANT -Wall -W $(DEFINES)
+INCPATH       = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I../.. -I../libdhcpcd -I.
+LINK          = g++
+LFLAGS        = 
+LIBS          = $(SUBLIBS)  -L/usr/lib64/qt4 -L../libdhcpcd ../libdhcpcd/libdhcpcd.a -lQtGui -L/usr/lib64 -L/usr/lib64/qt4 -L/usr/X11R6/lib -lQtCore -lgthread-2.0 -lglib-2.0 -lpthread 
+AR            = ar cqs
+RANLIB        = 
+QMAKE         = /usr/bin/qmake
+TAR           = tar -cf
+COMPRESS      = gzip -9f
+COPY          = cp -f
+SED           = sed
+COPY_FILE     = $(COPY)
+COPY_DIR      = $(COPY) -r
+STRIP         = strip
+INSTALL_FILE  = install -m 644 -p
+INSTALL_DIR   = $(COPY_DIR)
+INSTALL_PROGRAM = install -m 755 -p
+DEL_FILE      = rm -f
+SYMLINK       = ln -f -s
+DEL_DIR       = rmdir
+MOVE          = mv -f
+CHK_DIR_EXISTS= test -d
+MKDIR         = mkdir -p
+
+####### Output directory
+
+OBJECTS_DIR   = ./
+
+####### Files
+
+SOURCES       = main.cpp \
+               dhcpcd-qt.cpp \
+               dhcpcd-about.cpp \
+               dhcpcd-preferences.cpp \
+               dhcpcd-wi.cpp \
+               dhcpcd-ssidmenu.cpp moc_dhcpcd-qt.cpp \
+               moc_dhcpcd-about.cpp \
+               moc_dhcpcd-preferences.cpp \
+               moc_dhcpcd-wi.cpp \
+               moc_dhcpcd-ssidmenu.cpp
+OBJECTS       = main.o \
+               dhcpcd-qt.o \
+               dhcpcd-about.o \
+               dhcpcd-preferences.o \
+               dhcpcd-wi.o \
+               dhcpcd-ssidmenu.o \
+               moc_dhcpcd-qt.o \
+               moc_dhcpcd-about.o \
+               moc_dhcpcd-preferences.o \
+               moc_dhcpcd-wi.o \
+               moc_dhcpcd-ssidmenu.o
+DIST          = /usr/share/qt4/mkspecs/common/unix.conf \
+               /usr/share/qt4/mkspecs/common/linux.conf \
+               /usr/share/qt4/mkspecs/common/gcc-base.conf \
+               /usr/share/qt4/mkspecs/common/gcc-base-unix.conf \
+               /usr/share/qt4/mkspecs/common/g++-base.conf \
+               /usr/share/qt4/mkspecs/common/g++-unix.conf \
+               /usr/share/qt4/mkspecs/qconfig.pri \
+               /usr/share/qt4/mkspecs/modules/qt_phonon.pri \
+               /usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \
+               /usr/share/qt4/mkspecs/features/qt_functions.prf \
+               /usr/share/qt4/mkspecs/features/qt_config.prf \
+               /usr/share/qt4/mkspecs/features/exclusive_builds.prf \
+               /usr/share/qt4/mkspecs/features/default_pre.prf \
+               /usr/share/qt4/mkspecs/features/debug.prf \
+               /usr/share/qt4/mkspecs/features/default_post.prf \
+               /usr/share/qt4/mkspecs/features/qt.prf \
+               /usr/share/qt4/mkspecs/features/unix/thread.prf \
+               /usr/share/qt4/mkspecs/features/moc.prf \
+               /usr/share/qt4/mkspecs/features/shared.prf \
+               /usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \
+               /usr/share/qt4/mkspecs/features/warn_on.prf \
+               /usr/share/qt4/mkspecs/features/resources.prf \
+               /usr/share/qt4/mkspecs/features/uic.prf \
+               /usr/share/qt4/mkspecs/features/yacc.prf \
+               /usr/share/qt4/mkspecs/features/lex.prf \
+               /usr/share/qt4/mkspecs/features/include_source_dir.prf \
+               dhcpcd-qt.pro
+QMAKE_TARGET  = dhcpcd-qt
+DESTDIR       = 
+TARGET        = dhcpcd-qt
+
+first: all
+####### Implicit rules
+
+.SUFFIXES: .o .c .cpp .cc .cxx .C
+
+.cpp.o:
+       $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
+
+.cc.o:
+       $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
+
+.cxx.o:
+       $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
+
+.C.o:
+       $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
+
+.c.o:
+       $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"
+
+####### Build rules
+
+all: Makefile $(TARGET)
+
+$(TARGET):  $(OBJECTS)  
+       $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
+       { test -n "$(DESTDIR)" && DESTDIR="$(DESTDIR)" || DESTDIR=.; } && test $$(gdb --version | sed -e 's,[^0-9]\+\([0-9]\)\.\([0-9]\).*,\1\2,;q') -gt 72 && gdb --nx --batch --quiet -ex 'set confirm off' -ex "save gdb-index $$DESTDIR" -ex quit '$(TARGET)' && test -f $(TARGET).gdb-index && objcopy --add-section '.gdb_index=$(TARGET).gdb-index' --set-section-flags '.gdb_index=readonly' '$(TARGET)' '$(TARGET)' && rm -f $(TARGET).gdb-index || true
+
+Makefile: dhcpcd-qt.pro  /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/mkspecs/common/unix.conf \
+               /usr/share/qt4/mkspecs/common/linux.conf \
+               /usr/share/qt4/mkspecs/common/gcc-base.conf \
+               /usr/share/qt4/mkspecs/common/gcc-base-unix.conf \
+               /usr/share/qt4/mkspecs/common/g++-base.conf \
+               /usr/share/qt4/mkspecs/common/g++-unix.conf \
+               /usr/share/qt4/mkspecs/qconfig.pri \
+               /usr/share/qt4/mkspecs/modules/qt_phonon.pri \
+               /usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \
+               /usr/share/qt4/mkspecs/features/qt_functions.prf \
+               /usr/share/qt4/mkspecs/features/qt_config.prf \
+               /usr/share/qt4/mkspecs/features/exclusive_builds.prf \
+               /usr/share/qt4/mkspecs/features/default_pre.prf \
+               /usr/share/qt4/mkspecs/features/debug.prf \
+               /usr/share/qt4/mkspecs/features/default_post.prf \
+               /usr/share/qt4/mkspecs/features/qt.prf \
+               /usr/share/qt4/mkspecs/features/unix/thread.prf \
+               /usr/share/qt4/mkspecs/features/moc.prf \
+               /usr/share/qt4/mkspecs/features/shared.prf \
+               /usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \
+               /usr/share/qt4/mkspecs/features/warn_on.prf \
+               /usr/share/qt4/mkspecs/features/resources.prf \
+               /usr/share/qt4/mkspecs/features/uic.prf \
+               /usr/share/qt4/mkspecs/features/yacc.prf \
+               /usr/share/qt4/mkspecs/features/lex.prf \
+               /usr/share/qt4/mkspecs/features/include_source_dir.prf \
+               /usr/lib64/qt4/libQtGui.prl \
+               /usr/lib64/qt4/libQtCore.prl
+       $(QMAKE) -o Makefile dhcpcd-qt.pro
+/usr/share/qt4/mkspecs/common/unix.conf:
+/usr/share/qt4/mkspecs/common/linux.conf:
+/usr/share/qt4/mkspecs/common/gcc-base.conf:
+/usr/share/qt4/mkspecs/common/gcc-base-unix.conf:
+/usr/share/qt4/mkspecs/common/g++-base.conf:
+/usr/share/qt4/mkspecs/common/g++-unix.conf:
+/usr/share/qt4/mkspecs/qconfig.pri:
+/usr/share/qt4/mkspecs/modules/qt_phonon.pri:
+/usr/share/qt4/mkspecs/modules/qt_webkit_version.pri:
+/usr/share/qt4/mkspecs/features/qt_functions.prf:
+/usr/share/qt4/mkspecs/features/qt_config.prf:
+/usr/share/qt4/mkspecs/features/exclusive_builds.prf:
+/usr/share/qt4/mkspecs/features/default_pre.prf:
+/usr/share/qt4/mkspecs/features/debug.prf:
+/usr/share/qt4/mkspecs/features/default_post.prf:
+/usr/share/qt4/mkspecs/features/qt.prf:
+/usr/share/qt4/mkspecs/features/unix/thread.prf:
+/usr/share/qt4/mkspecs/features/moc.prf:
+/usr/share/qt4/mkspecs/features/shared.prf:
+/usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf:
+/usr/share/qt4/mkspecs/features/warn_on.prf:
+/usr/share/qt4/mkspecs/features/resources.prf:
+/usr/share/qt4/mkspecs/features/uic.prf:
+/usr/share/qt4/mkspecs/features/yacc.prf:
+/usr/share/qt4/mkspecs/features/lex.prf:
+/usr/share/qt4/mkspecs/features/include_source_dir.prf:
+/usr/lib64/qt4/libQtGui.prl:
+/usr/lib64/qt4/libQtCore.prl:
+qmake:  FORCE
+       @$(QMAKE) -o Makefile dhcpcd-qt.pro
+
+dist: 
+       @$(CHK_DIR_EXISTS) .tmp/dhcpcd-qt1.0.0 || $(MKDIR) .tmp/dhcpcd-qt1.0.0 
+       $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/dhcpcd-qt1.0.0/ && $(COPY_FILE) --parents dhcpcd-qt.h dhcpcd-about.h dhcpcd-preferences.h dhcpcd-wi.h dhcpcd-ssidmenu.h .tmp/dhcpcd-qt1.0.0/ && $(COPY_FILE) --parents main.cpp dhcpcd-qt.cpp dhcpcd-about.cpp dhcpcd-preferences.cpp dhcpcd-wi.cpp dhcpcd-ssidmenu.cpp .tmp/dhcpcd-qt1.0.0/ && (cd `dirname .tmp/dhcpcd-qt1.0.0` && $(TAR) dhcpcd-qt1.0.0.tar dhcpcd-qt1.0.0 && $(COMPRESS) dhcpcd-qt1.0.0.tar) && $(MOVE) `dirname .tmp/dhcpcd-qt1.0.0`/dhcpcd-qt1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/dhcpcd-qt1.0.0
+
+
+clean:compiler_clean 
+       -$(DEL_FILE) $(OBJECTS)
+       -$(DEL_FILE) ${TARGET}
+       -$(DEL_FILE) *~ core *.core
+
+
+####### Sub-libraries
+
+distclean: clean
+       -$(DEL_FILE) $(TARGET) 
+       -$(DEL_FILE) Makefile
+
+
+check: first
+
+mocclean: compiler_moc_header_clean compiler_moc_source_clean
+
+mocables: compiler_moc_header_make_all compiler_moc_source_make_all
+
+compiler_moc_header_make_all: moc_dhcpcd-qt.cpp moc_dhcpcd-about.cpp moc_dhcpcd-preferences.cpp moc_dhcpcd-wi.cpp moc_dhcpcd-ssidmenu.cpp
+compiler_moc_header_clean:
+       -$(DEL_FILE) moc_dhcpcd-qt.cpp moc_dhcpcd-about.cpp moc_dhcpcd-preferences.cpp moc_dhcpcd-wi.cpp moc_dhcpcd-ssidmenu.cpp
+moc_dhcpcd-qt.cpp: dhcpcd-wi.h \
+               dhcpcd-qt.h
+       /usr/bin/moc $(DEFINES) $(INCPATH) dhcpcd-qt.h -o moc_dhcpcd-qt.cpp
+
+moc_dhcpcd-about.cpp: dhcpcd-about.h
+       /usr/bin/moc $(DEFINES) $(INCPATH) dhcpcd-about.h -o moc_dhcpcd-about.cpp
+
+moc_dhcpcd-preferences.cpp: dhcpcd-preferences.h
+       /usr/bin/moc $(DEFINES) $(INCPATH) dhcpcd-preferences.h -o moc_dhcpcd-preferences.cpp
+
+moc_dhcpcd-wi.cpp: dhcpcd-wi.h
+       /usr/bin/moc $(DEFINES) $(INCPATH) dhcpcd-wi.h -o moc_dhcpcd-wi.cpp
+
+moc_dhcpcd-ssidmenu.cpp: dhcpcd-ssidmenu.h
+       /usr/bin/moc $(DEFINES) $(INCPATH) dhcpcd-ssidmenu.h -o moc_dhcpcd-ssidmenu.cpp
+
+compiler_rcc_make_all:
+compiler_rcc_clean:
+compiler_image_collection_make_all: qmake_image_collection.cpp
+compiler_image_collection_clean:
+       -$(DEL_FILE) qmake_image_collection.cpp
+compiler_moc_source_make_all:
+compiler_moc_source_clean:
+compiler_uic_make_all:
+compiler_uic_clean:
+compiler_yacc_decl_make_all:
+compiler_yacc_decl_clean:
+compiler_yacc_impl_make_all:
+compiler_yacc_impl_clean:
+compiler_lex_make_all:
+compiler_lex_clean:
+compiler_clean: compiler_moc_header_clean 
+
+####### Compile
+
+main.o: main.cpp dhcpcd-qt.h \
+               dhcpcd-wi.h
+       $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
+
+dhcpcd-qt.o: dhcpcd-qt.cpp dhcpcd-qt.h \
+               dhcpcd-wi.h \
+               dhcpcd-about.h \
+               dhcpcd-preferences.h \
+               dhcpcd-ssidmenu.h
+       $(CXX) -c $(CXXFLAGS) $(INCPATH) -o dhcpcd-qt.o dhcpcd-qt.cpp
+
+dhcpcd-about.o: dhcpcd-about.cpp dhcpcd-about.h \
+               dhcpcd-qt.h \
+               dhcpcd-wi.h
+       $(CXX) -c $(CXXFLAGS) $(INCPATH) -o dhcpcd-about.o dhcpcd-about.cpp
+
+dhcpcd-preferences.o: dhcpcd-preferences.cpp dhcpcd-preferences.h \
+               dhcpcd-qt.h \
+               dhcpcd-wi.h
+       $(CXX) -c $(CXXFLAGS) $(INCPATH) -o dhcpcd-preferences.o dhcpcd-preferences.cpp
+
+dhcpcd-wi.o: dhcpcd-wi.cpp dhcpcd-wi.h
+       $(CXX) -c $(CXXFLAGS) $(INCPATH) -o dhcpcd-wi.o dhcpcd-wi.cpp
+
+dhcpcd-ssidmenu.o: dhcpcd-ssidmenu.cpp dhcpcd-qt.h \
+               dhcpcd-wi.h \
+               dhcpcd-ssidmenu.h
+       $(CXX) -c $(CXXFLAGS) $(INCPATH) -o dhcpcd-ssidmenu.o dhcpcd-ssidmenu.cpp
+
+moc_dhcpcd-qt.o: moc_dhcpcd-qt.cpp 
+       $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_dhcpcd-qt.o moc_dhcpcd-qt.cpp
+
+moc_dhcpcd-about.o: moc_dhcpcd-about.cpp 
+       $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_dhcpcd-about.o moc_dhcpcd-about.cpp
+
+moc_dhcpcd-preferences.o: moc_dhcpcd-preferences.cpp 
+       $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_dhcpcd-preferences.o moc_dhcpcd-preferences.cpp
+
+moc_dhcpcd-wi.o: moc_dhcpcd-wi.cpp 
+       $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_dhcpcd-wi.o moc_dhcpcd-wi.cpp
+
+moc_dhcpcd-ssidmenu.o: moc_dhcpcd-ssidmenu.cpp 
+       $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_dhcpcd-ssidmenu.o moc_dhcpcd-ssidmenu.cpp
+
+####### Install
+
+install:   FORCE
+
+uninstall:   FORCE
+
+FORCE:
+
diff --git a/src/dhcpcd-qt/dhcpcd-about.cpp b/src/dhcpcd-qt/dhcpcd-about.cpp
new file mode 100644 (file)
index 0000000..eb0afce
--- /dev/null
@@ -0,0 +1,58 @@
+#include <QDialog>
+#include <QIcon>
+#include <QLabel>
+#include <QPixmap>
+#include <QPushButton>
+#include <QVBoxLayout>
+
+#include "config.h"
+#include "dhcpcd-about.h"
+#include "dhcpcd-qt.h"
+
+DhcpcdAbout::DhcpcdAbout(DhcpcdQt *parent)
+    : QDialog(NULL)
+{
+       QVBoxLayout *layout;
+
+       this->parent = parent;
+       resize(300, 200);
+       setWindowTitle("About dhcpcd-qt");
+       layout = new QVBoxLayout(this);
+
+       QIcon icon = DhcpcdQt::getIcon("status", "network-transmit-receive");
+       QPixmap picon = icon.pixmap(48, 48);
+       iconLabel = new QLabel(this);
+       iconLabel->setAlignment(Qt::AlignCenter);
+       iconLabel->setPixmap(picon);
+       layout->addWidget(iconLabel);
+
+       aboutLabel = new QLabel("<h1>Network Configurator "  VERSION "</h1>", this);
+       aboutLabel->setAlignment(Qt::AlignCenter);
+       layout->addWidget(aboutLabel);
+       partLabel = new QLabel("Part of the dhcpcd project", this);
+       partLabel->setAlignment(Qt::AlignCenter);
+       layout->addWidget(partLabel);
+       copyrightLabel = new QLabel("Copyright (c) 2009-2014 Roy Marples", this);
+       copyrightLabel->setAlignment(Qt::AlignCenter);
+       layout->addWidget(copyrightLabel);
+       urlLabel = new QLabel(
+           "<a href=\"http://roy.marples.name/projects/dhcpcd\">"
+           "dhcpcd Website"
+           "</a>",
+           this);
+       urlLabel->setAlignment(Qt::AlignCenter);
+       urlLabel->setOpenExternalLinks(true);
+       layout->addWidget(urlLabel);
+
+       closeButton = new QPushButton("Close", this);
+       closeButton->setIcon(QIcon::fromTheme("window-close"));
+       layout->addWidget(closeButton);
+       connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
+}
+
+void DhcpcdAbout::closeEvent(QCloseEvent *e)
+{
+
+       parent->dialogClosed(this);
+       QDialog::closeEvent(e);
+}
diff --git a/src/dhcpcd-qt/dhcpcd-about.h b/src/dhcpcd-qt/dhcpcd-about.h
new file mode 100644 (file)
index 0000000..02545c0
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef DHCPCD_ABOUT_H
+#define DHCPCD_ABOUT_H
+
+#include <QDialog>
+
+class DhcpcdQt;
+class QLabel;
+class QPushButton;
+
+class DhcpcdAbout : public QDialog
+{
+       Q_OBJECT
+
+public:
+       DhcpcdAbout(DhcpcdQt *parent = 0);
+
+protected:
+       void closeEvent(QCloseEvent *e);
+
+private:
+       DhcpcdQt *parent;
+       QLabel *iconLabel;
+       QLabel *aboutLabel;
+       QLabel *partLabel;
+       QLabel *copyrightLabel;
+       QLabel *urlLabel;
+       QPushButton *closeButton;
+};
+
+#endif
diff --git a/src/dhcpcd-qt/dhcpcd-preferences.cpp b/src/dhcpcd-qt/dhcpcd-preferences.cpp
new file mode 100644 (file)
index 0000000..f54a6c9
--- /dev/null
@@ -0,0 +1,32 @@
+#include <QDialog>
+#include <QIcon>
+#include <QLabel>
+#include <QPixmap>
+#include <QPushButton>
+#include <QVBoxLayout>
+
+#include "config.h"
+#include "dhcpcd-preferences.h"
+#include "dhcpcd-qt.h"
+
+DhcpcdPreferences::DhcpcdPreferences(DhcpcdQt *parent)
+    : QDialog(NULL)
+{
+       QVBoxLayout *layout;
+
+       this->parent = parent;
+       resize(300, 200);
+       setWindowTitle("dhcpcd-qt prefs");
+       layout = new QVBoxLayout(this);
+
+       notLabel = new QLabel("<h1>Not implemented yet</h1>", this);
+       notLabel->setAlignment(Qt::AlignCenter);
+       layout->addWidget(notLabel);
+}
+
+void DhcpcdPreferences::closeEvent(QCloseEvent *e)
+{
+
+       parent->dialogClosed(this);
+       QDialog::closeEvent(e);
+}
diff --git a/src/dhcpcd-qt/dhcpcd-preferences.h b/src/dhcpcd-qt/dhcpcd-preferences.h
new file mode 100644 (file)
index 0000000..4276ee7
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef DHCPCD_PREFERENCES_H
+#define DHCPCD_PREFERENCES_H
+
+#include <QDialog>
+
+class DhcpcdQt;
+class QLabel;
+
+class DhcpcdPreferences : public QDialog
+{
+       Q_OBJECT
+
+public:
+       DhcpcdPreferences(DhcpcdQt *parent = 0);
+
+protected:
+       void closeEvent(QCloseEvent *e);
+
+private:
+       DhcpcdQt *parent;
+       QLabel *notLabel;
+};
+
+#endif
diff --git a/src/dhcpcd-qt/dhcpcd-qt.cpp b/src/dhcpcd-qt/dhcpcd-qt.cpp
new file mode 100644 (file)
index 0000000..c305742
--- /dev/null
@@ -0,0 +1,483 @@
+#include <QCursor>
+#include <QDebug>
+#include <QList>
+#include <QSocketNotifier>
+#include <QtGui>
+
+#include <cerrno>
+
+#include "config.h"
+#include "dhcpcd-qt.h"
+#include "dhcpcd-about.h"
+#include "dhcpcd-preferences.h"
+#include "dhcpcd-wi.h"
+#include "dhcpcd-ssidmenu.h"
+
+DhcpcdQt::DhcpcdQt()
+{
+
+       createActions();
+       createTrayIcon();
+
+       onLine = carrier = false;
+       lastStatus = NULL;
+       aniTimer = new QTimer(this);
+       connect(aniTimer, SIGNAL(timeout()), this, SLOT(animate()));
+       retryOpenTimer = NULL;
+
+       about = NULL;
+       preferences = NULL;
+
+       wis = new QList<DhcpcdWi *>();
+       ssidMenu = NULL;
+
+       qDebug("%s", "Connecting ...");
+       con = dhcpcd_new();
+       if (con == NULL) {
+               qCritical("libdhcpcd: %s", strerror(errno));
+               exit(EXIT_FAILURE);
+               return;
+       }
+       dhcpcd_set_status_callback(con, dhcpcd_status_cb, this);
+       dhcpcd_set_if_callback(con, dhcpcd_if_cb, this);
+       dhcpcd_wpa_set_scan_callback(con, dhcpcd_wpa_scan_cb, this);
+       tryOpen();
+
+}
+
+DhcpcdQt::~DhcpcdQt()
+{
+
+       qDeleteAll(*wis);
+       delete wis;
+
+       free(lastStatus);
+
+       if (con != NULL) {
+               dhcpcd_close(con);
+               dhcpcd_free(con);
+       }
+}
+
+void DhcpcdQt::animate()
+{
+       const char *icon;
+
+       if (onLine) {
+               if (aniCounter++ > 6) {
+                       aniTimer->stop();
+                       aniCounter = 0;
+                       return;
+               }
+
+               if (aniCounter % 2 == 0)
+                       icon = "network-idle";
+               else
+                       icon = "network-transmit-receive";
+       } else {
+               switch(aniCounter++) {
+               case 0:
+                       icon = "network-transmit";
+                       break;
+               case 1:
+                       icon = "network-receive";
+                       break;
+               default:
+                       icon = "network-idle";
+                       aniCounter = 0;
+               }
+       }
+
+       setIcon("status", icon);
+}
+
+void DhcpcdQt::updateOnline(bool showIf)
+{
+       bool isOn, isCarrier;
+       char *msg;
+       DHCPCD_IF *ifs, *i;
+       QString msgs;
+
+       isOn = isCarrier = false;
+       ifs = dhcpcd_interfaces(con);
+       for (i = ifs; i; i = i->next) {
+               if (strcmp(i->type, "link") == 0) {
+                       if (i->up)
+                               isCarrier = true;
+               } else {
+                       if (i->up)
+                               isOn = true;
+               }
+               msg = dhcpcd_if_message(i, NULL);
+               if (msg) {
+                       if (showIf)
+                               qDebug() << msg;
+                       if (msgs.isEmpty())
+                               msgs = QString::fromAscii(msg);
+                       else
+                               msgs += '\n' + QString::fromAscii(msg);
+                       free(msg);
+               } else if (showIf)
+                       qDebug() << i->ifname << i->reason;
+       }
+
+       if (onLine != isOn || carrier != isCarrier) {
+               onLine = isOn;
+               aniTimer->stop();
+               aniCounter = 0;
+               if (isOn) {
+                       animate();
+                       aniTimer->start(300);
+               } else if (isCarrier) {
+                       animate();
+                       aniTimer->start(500);
+               } else
+                       setIcon("status", "network-offline");
+       }
+
+       trayIcon->setToolTip(msgs);
+}
+
+void DhcpcdQt::statusCallback(const char *status)
+{
+
+       qDebug("Status changed to %s", status);
+       if (strcmp(status, "down") == 0) {
+               QString msg;
+               if (lastStatus)
+                       msg = tr("Connection to dhcpcd lost");
+               else
+                       msg = tr("dhcpcd not running");
+               aniTimer->stop();
+               aniCounter = 0;
+               setIcon("status", "network-offline");
+       } else {
+               bool refresh;
+
+               if ((lastStatus == NULL || strcmp(lastStatus, "down") == 0)) {
+                       qDebug("Connected to dhcpcd-%s", dhcpcd_version(con));
+                       refresh = true;
+               } else
+                       refresh = false;
+               updateOnline(refresh);
+       }
+
+       free(lastStatus);
+       lastStatus = strdup(status);
+}
+
+void DhcpcdQt::dhcpcd_status_cb(_unused DHCPCD_CONNECTION *con,
+    const char *status, void *d)
+{
+       DhcpcdQt *dhcpcdQt = (DhcpcdQt *)d;
+
+       dhcpcdQt->statusCallback(status);
+}
+
+void DhcpcdQt::ifCallback(DHCPCD_IF *i)
+{
+       char *msg;
+       bool new_msg;
+
+       updateOnline(false);
+
+       if (strcmp(i->reason, "RENEW") == 0 ||
+           strcmp(i->reason, "STOP") == 0 ||
+           strcmp(i->reason, "STOPPED") == 0)
+               return;
+
+       msg = dhcpcd_if_message(i, &new_msg);
+       if (msg) {
+               qDebug("%s", msg);
+               if (new_msg) {
+                       QSystemTrayIcon::MessageIcon icon =
+                           i->up ? QSystemTrayIcon::Information :
+                           QSystemTrayIcon::Warning;
+                       trayIcon->showMessage(tr("Network Event"), msg, icon);
+               }
+               free(msg);
+       }
+}
+
+void DhcpcdQt::dhcpcd_if_cb(DHCPCD_IF *i, void *d)
+{
+       DhcpcdQt *dhcpcdQt = (DhcpcdQt *)d;
+
+       dhcpcdQt->ifCallback(i);
+}
+
+DhcpcdWi *DhcpcdQt::findWi(DHCPCD_WPA *wpa)
+{
+
+       for (auto &wi : *wis) {
+               if (wi->getWpa() == wpa)
+                       return wi;
+       }
+       return NULL;
+}
+
+void DhcpcdQt::scanCallback(DHCPCD_WPA *wpa)
+{
+       DHCPCD_WI_SCAN *scans, *s1, *s2;
+       int fd = dhcpcd_wpa_get_fd(wpa);
+       DhcpcdWi *wi;
+
+       wi = findWi(wpa);
+       if (fd == -1) {
+               qCritical("No fd for WPA");
+               if (wi) {
+                       wis->removeOne(wi);
+                       delete wi;
+               }
+               return;
+       }
+
+       DHCPCD_IF *i = dhcpcd_wpa_if(wpa);
+       if (i == NULL) {
+               qCritical("No interface for WPA");
+               if (wi) {
+                       wis->removeOne(wi);
+                       delete wi;
+               }
+               return;
+       }
+
+       qDebug("%s: Received scan results", i->ifname);
+       scans = dhcpcd_wi_scans(i);
+       if (wi == NULL) {
+               wi = new DhcpcdWi(this, wpa);
+               wis->append(wi);
+       } else {
+               QString title = tr("New Access Point");
+               QString txt;
+               for (s1 = scans; s1; s1 = s1->next) {
+                       for (s2 = wi->getScans(); s2; s2 = s2->next) {
+                               if (strcmp(s1->ssid, s2->ssid) == 0)
+                                       break;
+                               if (s2 == NULL) {
+                                       if (!txt.isEmpty()) {
+                                               title = tr("New Access Points");
+                                               txt += '\n';
+                                       }
+                                       txt += s1->ssid;
+                               }
+                       }
+               }
+               if (!txt.isEmpty())
+                       notify(title, txt);
+       }
+       wi->setScans(scans);
+}
+
+void DhcpcdQt::dhcpcd_wpa_scan_cb(DHCPCD_WPA *wpa, void *d)
+{
+       DhcpcdQt *dhcpcdQt = (DhcpcdQt *)d;
+
+       dhcpcdQt->scanCallback(wpa);
+}
+
+bool DhcpcdQt::tryOpen() {
+       int fd = dhcpcd_open(con);
+       static int last_error;
+
+       if (fd == -1) {
+               if (errno != last_error) {
+                       last_error = errno;
+                       qCritical("dhcpcd_open: %s", strerror(errno));
+               }
+               if (retryOpenTimer == NULL) {
+                       retryOpenTimer = new QTimer(this);
+                       connect(retryOpenTimer, SIGNAL(timeout()),
+                           this, SLOT(tryOpen()));
+                       retryOpenTimer->start(DHCPCD_RETRYOPEN);
+               }
+               return false;
+       }
+
+       if (retryOpenTimer) {
+               delete retryOpenTimer;
+               retryOpenTimer = NULL;
+       }
+
+       notifier = new QSocketNotifier(fd, QSocketNotifier::Read);
+       connect(notifier, SIGNAL(activated(int)), this, SLOT(dispatch()));
+
+       return true;
+}
+
+void DhcpcdQt::dispatch() {
+
+       if (dhcpcd_get_fd(con) == -1) {
+               qWarning("dhcpcd connection lost");
+               return;
+       }
+
+       dhcpcd_dispatch(con);
+}
+
+void DhcpcdQt::notify(QString &title, QString &msg,
+    QSystemTrayIcon::MessageIcon icon)
+{
+
+       qDebug("%s", qPrintable(msg));
+       trayIcon->showMessage(title, msg, icon);
+}
+
+
+void DhcpcdQt::closeEvent(QCloseEvent *event)
+{
+
+       if (trayIcon->isVisible()) {
+               hide();
+               event->ignore();
+       }
+}
+
+QIcon DhcpcdQt::getIcon(QString category, QString name)
+{
+       QIcon icon;
+
+       if (QIcon::hasThemeIcon(name))
+               icon = QIcon::fromTheme(name);
+       else
+               icon = QIcon(ICONDIR "/hicolor/scalable/" + category + "/" + name + ".svg");
+       return icon;
+}
+
+void DhcpcdQt::setIcon(QString category, QString name)
+{
+       QIcon icon = getIcon(category, name);
+
+       trayIcon->setIcon(icon);
+}
+
+QIcon DhcpcdQt::icon()
+{
+
+       return getIcon("status", "network-transmit-receive");
+}
+
+void DhcpcdQt::addSsidMenu(QMenu *&menu, DHCPCD_IF *ifp, DhcpcdWi *&wi)
+{
+       DHCPCD_WI_SCAN *scan;
+
+       for (scan = wi->getScans(); scan; scan = scan->next) {
+               QWidgetAction *wa = new QWidgetAction(menu);
+               DhcpcdSsidMenu *ssidMenu = new DhcpcdSsidMenu(menu, ifp, scan);
+               wa->setDefaultWidget(ssidMenu);
+               menu->addAction(wa);
+               connect(ssidMenu, SIGNAL(selected(DHCPCD_IF *, DHCPCD_WI_SCAN *)),
+                   this, SLOT(connectSsid(DHCPCD_IF *, DHCPCD_WI_SCAN *)));
+       }
+}
+
+void DhcpcdQt::connectSsid(DHCPCD_IF *, DHCPCD_WI_SCAN *)
+{
+
+       QMessageBox::information(this, "Not implemented",
+           "SSID selection is not yet implemented");
+}
+
+void DhcpcdQt::createSsidMenu()
+{
+       DHCPCD_WPA *wpa;
+       DHCPCD_IF *ifp;
+
+       if (ssidMenu) {
+               delete ssidMenu;
+               ssidMenu = NULL;
+       }
+       if (wis->size() == 0)
+               return;
+
+       ssidMenu = new QMenu(this);
+       if (wis->size() == 1) {
+               DhcpcdWi *wi = wis->first();
+               wpa = wi->getWpa();
+               ifp = dhcpcd_wpa_if(wpa);
+               addSsidMenu(ssidMenu, ifp, wi);
+       } else {
+               for (auto &wi : *wis) {
+                       wpa = wi->getWpa();
+                       ifp = dhcpcd_wpa_if(wpa);
+                       if (ifp) {
+                               QMenu *ifmenu = ssidMenu->addMenu(ifp->ifname);
+                               addSsidMenu(ifmenu, ifp, wi);
+                       }
+               }
+       }
+       ssidMenu->popup(QCursor::pos());
+}
+
+void DhcpcdQt::iconActivated(QSystemTrayIcon::ActivationReason reason)
+{
+
+       if (reason == QSystemTrayIcon::Trigger)
+               createSsidMenu();
+}
+
+void DhcpcdQt::dialogClosed(QDialog *dialog)
+{
+
+       if (dialog == about)
+               about = NULL;
+       else if (dialog == preferences)
+               preferences = NULL;
+}
+
+void DhcpcdQt::showPreferences()
+{
+
+       if (preferences == NULL) {
+               preferences = new DhcpcdPreferences(this);
+               preferences->show();
+       } else
+               preferences->activateWindow();
+}
+
+void DhcpcdQt::showAbout()
+{
+
+       if (about == NULL) {
+               about = new DhcpcdAbout(this);
+               about->show();
+       } else
+               about->activateWindow();
+}
+
+void DhcpcdQt::createActions()
+{
+
+       preferencesAction = new QAction(tr("&Preferences"), this);
+       preferencesAction->setIcon(QIcon::fromTheme("preferences-system-network"));
+       connect(preferencesAction, SIGNAL(triggered()),
+           this, SLOT(showPreferences()));
+
+       aboutAction = new QAction(tr("&About"), this);
+       aboutAction->setIcon(QIcon::fromTheme("help-about"));
+       connect(aboutAction, SIGNAL(triggered()), this, SLOT(showAbout()));
+
+       quitAction = new QAction(tr("&Quit"), this);
+       quitAction->setIcon(QIcon::fromTheme("application-exit"));
+       connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+
+}
+
+void DhcpcdQt::createTrayIcon()
+{
+
+        trayIconMenu = new QMenu(this);
+       trayIconMenu->addAction(preferencesAction);
+       trayIconMenu->addSeparator();
+       trayIconMenu->addAction(aboutAction);
+       trayIconMenu->addAction(quitAction);
+
+       trayIcon = new QSystemTrayIcon(this);
+       setIcon("status", "network-offline");
+       trayIcon->setContextMenu(trayIconMenu);
+
+       connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
+           this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
+
+       trayIcon->show();
+}
diff --git a/src/dhcpcd-qt/dhcpcd-qt.h b/src/dhcpcd-qt/dhcpcd-qt.h
new file mode 100644 (file)
index 0000000..019d6a8
--- /dev/null
@@ -0,0 +1,98 @@
+#ifndef DHCPCD_QT_H
+#define DHCPCD_QT_H
+
+#include <QSystemTrayIcon>
+#include <QWidget>
+
+#include "dhcpcd.h"
+#include "dhcpcd-wi.h"
+
+#ifdef __GNUC__
+#  define _unused __attribute__((__unused__))
+#else
+#  define _unused
+#endif
+
+class QAction;
+class QDialog;
+class QLabel;
+class QMenu;
+class QPushButton;
+class QSocketNotifier;
+class QTimer;
+
+class DhcpcdQt : public QWidget
+{
+       Q_OBJECT
+
+public:
+       DhcpcdQt();
+       ~DhcpcdQt();
+
+       void closeAbout();
+
+       static void dhcpcd_status_cb(DHCPCD_CONNECTION *con,
+           const char *status, void *d);
+       void statusCallback(const char *status);
+       static void dhcpcd_if_cb(DHCPCD_IF *i, void *d);
+       void ifCallback(DHCPCD_IF *i);
+
+       static void dhcpcd_wpa_scan_cb(DHCPCD_WPA *wpa, void *d);
+       void scanCallback(DHCPCD_WPA *wpa);
+
+       static QIcon getIcon(QString category, QString name);
+
+       void dialogClosed(QDialog *dialog);
+
+protected:
+       void closeEvent(QCloseEvent *event);
+
+private slots:
+       void animate();
+       void dispatch();
+       void showAbout();
+       void showPreferences();
+       void iconActivated(QSystemTrayIcon::ActivationReason reason);
+
+       void connectSsid(DHCPCD_IF *ifp, DHCPCD_WI_SCAN *scan);
+
+private:
+       DHCPCD_CONNECTION *con;
+       bool tryOpen();
+       QSocketNotifier *notifier;
+       QTimer *retryOpenTimer;
+       QList<DhcpcdWi *> *wis;
+       DhcpcdWi *findWi(DHCPCD_WPA *wpa);
+
+       char *lastStatus;
+       bool onLine;
+       bool carrier;
+       QTimer *aniTimer;
+       int aniCounter;
+       void updateOnline(bool showIf);
+
+       QDialog *about;
+       QDialog *preferences;
+
+       void addSsidMenu(QMenu *&menu, DHCPCD_IF *ifp, DhcpcdWi *&wi);
+       void createSsidMenu();
+
+       /* Tray Icon */
+       void setIcon(QString category, QString name);
+       QIcon icon();
+       void createActions();
+       void createTrayIcon();
+
+       QSystemTrayIcon *trayIcon;
+       QIcon *realTrayIcon;
+       QAction *preferencesAction;
+       QAction *quitAction;
+       QAction *aboutAction;
+       QMenu *trayIconMenu;
+       QMenu *ssidMenu;
+
+       void notify(QString &title, QString &msg,
+           QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information);
+};
+
+#endif
diff --git a/src/dhcpcd-qt/dhcpcd-qt.pro b/src/dhcpcd-qt/dhcpcd-qt.pro
new file mode 100644 (file)
index 0000000..d5c06ae
--- /dev/null
@@ -0,0 +1,14 @@
+CONFIG+=               qt gui c++11 debug
+QMAKE_CXXFLAGS+=       -std=c++11
+
+HEADERS=               dhcpcd-qt.h dhcpcd-about.h dhcpcd-preferences.h \
+                       dhcpcd-wi.h dhcpcd-ssidmenu.h
+SOURCES=               main.cpp dhcpcd-qt.cpp dhcpcd-about.cpp \
+                       dhcpcd-preferences.cpp dhcpcd-wi.cpp dhcpcd-ssidmenu.cpp
+
+INCLUDEPATH+=          ../../
+INCLUDEPATH+=          ../libdhcpcd/
+
+LIBS+=                 -L../libdhcpcd ../libdhcpcd/libdhcpcd.a
+
+QMAKE_CLEAN+=          ${TARGET}
diff --git a/src/dhcpcd-qt/dhcpcd-ssidmenu.cpp b/src/dhcpcd-qt/dhcpcd-ssidmenu.cpp
new file mode 100644 (file)
index 0000000..9316435
--- /dev/null
@@ -0,0 +1,61 @@
+#include <QWidget>
+#include <QEvent>
+#include <QHBoxLayout>
+#include <QRadioButton>
+#include <QIcon>
+#include <QLabel>
+#include <QPixmap>
+#include <QProgressBar>
+
+#include "dhcpcd.h"
+#include "dhcpcd-qt.h"
+#include "dhcpcd-ssidmenu.h"
+
+DhcpcdSsidMenu::DhcpcdSsidMenu(QWidget *parent, DHCPCD_IF *ifp, DHCPCD_WI_SCAN *scan)
+    : QWidget(parent, NULL)
+{
+       int strength;
+       QIcon icon;
+
+       this->ifp = ifp;
+       this->scan = scan;
+
+       QHBoxLayout *layout = new QHBoxLayout(this);
+       button = new QRadioButton(scan->ssid, this);
+       button->setChecked(strcmp(scan->ssid, ifp->ssid) == 0);
+       layout->addWidget(button);
+       if (scan->flags[0] == '\0') {
+               icon = DhcpcdQt::getIcon("devices", "network-wireless");
+               setToolTip(scan->bssid);
+       } else {
+               icon = DhcpcdQt::getIcon("status", "network-wireless-encrypted");
+               QString tip = QString::fromAscii(scan->bssid);
+               tip += " " + QString::fromAscii(scan->flags);
+               setToolTip(tip);
+       }
+       QPixmap picon = icon.pixmap(22, 22);
+       licon = new QLabel(this);
+       licon->setPixmap(picon);
+       layout->addWidget(licon);
+       bar = new QProgressBar(this);
+       bar->setMinimum(0);
+       bar->setMaximum(100);
+       if (scan->quality.value == 0)
+           strength = scan->level.average;
+       else
+           strength = scan->quality.average;
+       bar->setValue(strength < 0 ? 0 : strength > 100 ? 100 : strength);
+       layout->addWidget(bar);
+
+       button->installEventFilter(this);
+       licon->installEventFilter(this);
+       bar->installEventFilter(this);
+}
+
+bool DhcpcdSsidMenu::eventFilter(QObject *, QEvent *event)
+{
+
+       if (event->type() == QEvent::MouseButtonPress)
+               emit selected(ifp, scan);
+       return false;
+}
diff --git a/src/dhcpcd-qt/dhcpcd-ssidmenu.h b/src/dhcpcd-qt/dhcpcd-ssidmenu.h
new file mode 100644 (file)
index 0000000..30304c8
--- /dev/null
@@ -0,0 +1,30 @@
+#include <QWidget>
+
+#include "dhcpcd.h"
+
+class QRadioButton;
+class QLabel;
+class QProgressBar;
+
+class DhcpcdSsidMenu : public QWidget
+{
+       Q_OBJECT
+
+public:
+       DhcpcdSsidMenu(QWidget *parent, DHCPCD_IF *ifp, DHCPCD_WI_SCAN *scan);
+       ~DhcpcdSsidMenu() {};
+
+signals:
+       void selected(DHCPCD_IF *ifp, DHCPCD_WI_SCAN *scan);
+
+private slots:
+       bool eventFilter(QObject *obj, QEvent *event);
+
+private:
+       DHCPCD_IF *ifp;
+       DHCPCD_WI_SCAN *scan;
+
+       QRadioButton *button;
+       QLabel *licon;
+       QProgressBar *bar;
+};
diff --git a/src/dhcpcd-qt/dhcpcd-wi.cpp b/src/dhcpcd-qt/dhcpcd-wi.cpp
new file mode 100644 (file)
index 0000000..6eac5ff
--- /dev/null
@@ -0,0 +1,96 @@
+#include <QObject>
+#include <QSocketNotifier>
+#include <QTimer>
+
+#include <cerrno>
+
+#include "config.h"
+#include "dhcpcd-wi.h"
+
+DhcpcdWi::DhcpcdWi(DhcpcdQt *parent, DHCPCD_WPA *wpa)
+{
+
+       this->dhcpcdQt = parent;
+       this->wpa = wpa;
+       scans = NULL;
+
+       int fd = dhcpcd_wpa_get_fd(wpa);
+       notifier = new QSocketNotifier(fd, QSocketNotifier::Read);
+       connect(notifier, SIGNAL(activated(int)), this, SLOT(dispatch()));
+       retryOpenTimer = NULL;
+}
+
+DhcpcdWi::~DhcpcdWi()
+{
+
+       dhcpcd_wi_scans_free(scans);
+       if (notifier != NULL)
+               delete notifier;
+}
+
+DHCPCD_WPA * DhcpcdWi::getWpa()
+{
+
+       return wpa;
+}
+
+DHCPCD_WI_SCAN *DhcpcdWi::getScans()
+{
+
+       return scans;
+}
+void DhcpcdWi::setScans(DHCPCD_WI_SCAN *scans)
+{
+
+       dhcpcd_wi_scans_free(this->scans);
+       this->scans = scans;
+}
+
+void DhcpcdWi::wpaOpen()
+{
+       int fd = dhcpcd_wpa_open(wpa);
+       static int last_error;
+
+       if (fd == -1) {
+               if (errno != last_error) {
+                       last_error = errno;
+                       qCritical("%s: dhcpcd_wpa_open: %s",
+                           dhcpcd_wpa_if(wpa)->ifname,
+                           strerror(last_error));
+               }
+               return;
+       }
+
+       notifier = new QSocketNotifier(fd, QSocketNotifier::Read);
+       connect(notifier, SIGNAL(activated(int)), this, SLOT(dispatch()));
+       if (retryOpenTimer) {
+               delete retryOpenTimer;
+               retryOpenTimer = NULL;
+       }
+}
+
+void DhcpcdWi::dispatch()
+{
+
+       if (dhcpcd_wpa_get_fd(wpa) == -1) {
+               delete notifier;
+               notifier = NULL;
+               DHCPCD_IF *i = dhcpcd_wpa_if(wpa);
+               if (i == NULL ||
+                   strcmp(i->reason, "DEPARTED") == 0 ||
+                   strcmp(i->reason, "STOPPED") == 0)
+                       return;
+               qWarning("%s: %s",
+                   i->ifname,
+                   qPrintable(tr("dhcpcd WPA connection lost")));
+               if (retryOpenTimer == NULL) {
+                       retryOpenTimer = new QTimer(this);
+                       connect(retryOpenTimer, SIGNAL(timeout()),
+                           this, SLOT(wpaOpen()));
+                       retryOpenTimer->start(DHCPCD_RETRYOPEN);
+               }
+               return;
+       }
+
+       dhcpcd_wpa_dispatch(wpa);
+}
diff --git a/src/dhcpcd-qt/dhcpcd-wi.h b/src/dhcpcd-qt/dhcpcd-wi.h
new file mode 100644 (file)
index 0000000..bca289d
--- /dev/null
@@ -0,0 +1,37 @@
+#ifndef DHCPCD_WI_H
+#define DHCPCD_WI_H
+
+#include <QObject>
+
+#include "dhcpcd.h"
+
+class DhcpcdQt;
+class QSocketNotifier;
+class QTimer;
+
+class DhcpcdWi : public QObject
+{
+       Q_OBJECT
+
+public:
+       DhcpcdWi(DhcpcdQt *dhcpcdQt, DHCPCD_WPA *wpa);
+       ~DhcpcdWi();
+       DHCPCD_WPA *getWpa();
+
+       DHCPCD_WI_SCAN *getScans();
+       void setScans(DHCPCD_WI_SCAN *scans);
+
+private slots:
+       void dispatch();
+       void wpaOpen();
+
+private:
+       DhcpcdQt *dhcpcdQt;
+       DHCPCD_WPA *wpa;
+       DHCPCD_WI_SCAN *scans;
+
+       QSocketNotifier *notifier;
+       QTimer *retryOpenTimer;
+};
+
+#endif
diff --git a/src/dhcpcd-qt/main.cpp b/src/dhcpcd-qt/main.cpp
new file mode 100644 (file)
index 0000000..ad618d1
--- /dev/null
@@ -0,0 +1,21 @@
+#include <QtGui>
+
+#include "dhcpcd-qt.h"
+
+int
+main(int argc, char **argv)
+{
+
+       QApplication app(argc, argv);
+
+       if (!QSystemTrayIcon::isSystemTrayAvailable()) {
+               QMessageBox::critical(0, QObject::tr("Systray"),
+                   QObject::tr("No system tray available"));
+               return EXIT_FAILURE;
+       }
+
+       QApplication::setQuitOnLastWindowClosed(false);
+
+       DhcpcdQt dhcpcdQt;
+       return app.exec();
+}