From 5e39cf3599a12e1a52cda8a8a0c7064e81678f5f Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sat, 4 May 2013 13:15:01 +0200 Subject: [PATCH] traymonitor redesign - traymonitor redesign by Frank Ueberschar - traymon animated shows - added bareos icon to traymon, installer and fd executable Signed-off-by: Marco van Wieringen --- AUTHORS | 1 + autoconf/configure.in | 14 +- platforms/win32/tray-monitor-conf.patch | 6 +- platforms/win32/winbareos-nsi.spec | 8 +- platforms/win32/winbareos.nsi | 76 +-- platforms/win32/winbareos32.spec | 2 +- platforms/win32/winbareos64.spec | 2 +- src/console/console.c | 4 +- .../images/applications-graphics.svg | 0 src/images/bat.svg | 78 +++ src/{qt-console => }/images/browse.svg | 0 .../images/cartridge-edit.svg | 0 src/{qt-console => }/images/cartridge.svg | 0 src/{qt-console => }/images/check.svg | 0 src/{qt-console => }/images/edit-delete.svg | 0 src/{qt-console => }/images/emblem-system.svg | 0 src/{qt-console => }/images/estimate-job.svg | 0 src/{qt-console => }/images/folder.svg | 0 .../images/folderbothchecked.svg | 0 src/{qt-console => }/images/folderchecked.svg | 0 .../images/folderunchecked.svg | 0 src/{qt-console => }/images/go-down.svg | 0 src/{qt-console => }/images/go-jump.svg | 0 src/{qt-console => }/images/go-up.svg | 0 src/{qt-console => }/images/graph1.svg | 0 src/{qt-console => }/images/help-browser.svg | 0 src/{qt-console => }/images/joblog.svg | 0 .../images/mail-message-new.svg | 0 .../images/mail-message-pending.svg | 0 src/{qt-console => }/images/media-floppy.svg | 0 .../images/network-server.svg | 0 .../images/package-x-generic.svg | 0 .../images/status-console.svg | 0 src/{qt-console => }/images/status.svg | 0 .../images/system-file-manager.svg | 0 src/{qt-console => }/images/unchecked.svg | 0 .../images/utilities-terminal.svg | 0 src/{qt-console => }/images/view-refresh.svg | 0 .../images/weather-severe-alert.svg | 0 src/include/baconfig.h | 6 +- src/qt-console/bat.pro.in | 8 +- src/qt-console/main.qrc | 148 +++--- src/qt-console/mainwin.cpp | 19 +- src/qt-console/tray-monitor/tray-monitor.cpp | 465 ------------------ src/qt-console/tray-monitor/tray-monitor.h | 181 ------- src/qt-console/tray-monitor/tray-ui.h | 392 --------------- .../authenticate.cpp | 38 +- src/qt-tray-monitor/authenticate.h | 10 + .../bareos-tray-monitor.desktop | 13 + .../bareos-tray-monitor.desktop.in | 0 .../bareos-tray-monitor.xpm | 0 src/qt-tray-monitor/main.qrc | 8 + src/qt-tray-monitor/mainwindow.cpp | 200 ++++++++ src/qt-tray-monitor/mainwindow.h | 92 ++++ src/qt-tray-monitor/mainwindow.ui | 62 +++ src/qt-tray-monitor/monitoritem.cpp | 353 +++++++++++++ src/qt-tray-monitor/monitoritem.h | 136 +++++ src/qt-tray-monitor/monitoritemthread.cpp | 228 +++++++++ src/qt-tray-monitor/monitoritemthread.h | 75 +++ src/qt-tray-monitor/monitortab.h | 33 ++ src/qt-tray-monitor/systemtrayicon.cpp | 76 +++ src/qt-tray-monitor/systemtrayicon.h | 54 ++ .../tray-monitor.conf.in | 0 src/qt-tray-monitor/tray-monitor.cpp | 231 +++++++++ src/qt-tray-monitor/tray-monitor.h | 48 ++ .../tray-monitor.pro.in | 12 +- .../tray_conf.cpp | 11 +- .../tray_conf.h | 13 +- src/qt-tray-monitor/traymenu.cpp | 63 +++ src/qt-tray-monitor/traymenu.h | 45 ++ src/win32/Makefile.inc | 2 + src/win32/filed/Makefile | 12 +- src/win32/filed/icon.rc | 25 + src/win32/qt-console/bat.pro | 2 +- src/win32/qt-tray-monitor/tray-monitor.pro | 22 +- 75 files changed, 2070 insertions(+), 1204 deletions(-) rename src/{qt-console => }/images/applications-graphics.svg (100%) create mode 100644 src/images/bat.svg rename src/{qt-console => }/images/browse.svg (100%) rename src/{qt-console => }/images/cartridge-edit.svg (100%) rename src/{qt-console => }/images/cartridge.svg (100%) rename src/{qt-console => }/images/check.svg (100%) rename src/{qt-console => }/images/edit-delete.svg (100%) rename src/{qt-console => }/images/emblem-system.svg (100%) rename src/{qt-console => }/images/estimate-job.svg (100%) rename src/{qt-console => }/images/folder.svg (100%) rename src/{qt-console => }/images/folderbothchecked.svg (100%) rename src/{qt-console => }/images/folderchecked.svg (100%) rename src/{qt-console => }/images/folderunchecked.svg (100%) rename src/{qt-console => }/images/go-down.svg (100%) rename src/{qt-console => }/images/go-jump.svg (100%) rename src/{qt-console => }/images/go-up.svg (100%) rename src/{qt-console => }/images/graph1.svg (100%) rename src/{qt-console => }/images/help-browser.svg (100%) rename src/{qt-console => }/images/joblog.svg (100%) rename src/{qt-console => }/images/mail-message-new.svg (100%) rename src/{qt-console => }/images/mail-message-pending.svg (100%) rename src/{qt-console => }/images/media-floppy.svg (100%) rename src/{qt-console => }/images/network-server.svg (100%) rename src/{qt-console => }/images/package-x-generic.svg (100%) rename src/{qt-console => }/images/status-console.svg (100%) rename src/{qt-console => }/images/status.svg (100%) rename src/{qt-console => }/images/system-file-manager.svg (100%) rename src/{qt-console => }/images/unchecked.svg (100%) rename src/{qt-console => }/images/utilities-terminal.svg (100%) rename src/{qt-console => }/images/view-refresh.svg (100%) rename src/{qt-console => }/images/weather-severe-alert.svg (100%) delete mode 100644 src/qt-console/tray-monitor/tray-monitor.cpp delete mode 100644 src/qt-console/tray-monitor/tray-monitor.h delete mode 100644 src/qt-console/tray-monitor/tray-ui.h rename src/{qt-console/tray-monitor => qt-tray-monitor}/authenticate.cpp (83%) create mode 100644 src/qt-tray-monitor/authenticate.h create mode 100644 src/qt-tray-monitor/bareos-tray-monitor.desktop rename src/{qt-console/tray-monitor => qt-tray-monitor}/bareos-tray-monitor.desktop.in (100%) rename src/{qt-console/tray-monitor => qt-tray-monitor}/bareos-tray-monitor.xpm (100%) create mode 100644 src/qt-tray-monitor/main.qrc create mode 100644 src/qt-tray-monitor/mainwindow.cpp create mode 100644 src/qt-tray-monitor/mainwindow.h create mode 100644 src/qt-tray-monitor/mainwindow.ui create mode 100644 src/qt-tray-monitor/monitoritem.cpp create mode 100644 src/qt-tray-monitor/monitoritem.h create mode 100644 src/qt-tray-monitor/monitoritemthread.cpp create mode 100644 src/qt-tray-monitor/monitoritemthread.h create mode 100644 src/qt-tray-monitor/monitortab.h create mode 100644 src/qt-tray-monitor/systemtrayicon.cpp create mode 100644 src/qt-tray-monitor/systemtrayicon.h rename src/{qt-console/tray-monitor => qt-tray-monitor}/tray-monitor.conf.in (100%) create mode 100644 src/qt-tray-monitor/tray-monitor.cpp create mode 100644 src/qt-tray-monitor/tray-monitor.h rename src/{qt-console/tray-monitor => qt-tray-monitor}/tray-monitor.pro.in (79%) rename src/{qt-console/tray-monitor => qt-tray-monitor}/tray_conf.cpp (97%) rename src/{qt-console/tray-monitor => qt-tray-monitor}/tray_conf.h (93%) create mode 100644 src/qt-tray-monitor/traymenu.cpp create mode 100644 src/qt-tray-monitor/traymenu.h create mode 100644 src/win32/filed/icon.rc diff --git a/AUTHORS b/AUTHORS index 64ac2c31f79..8fd5357593c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -43,6 +43,7 @@ Felix Schwarz Francisco Reyes Frank Kardel Frank Sweetser +Frank Ueberschar Graham Keeling Grzegorz Grabowski Howard Thomson diff --git a/autoconf/configure.in b/autoconf/configure.in index c084776dd21..0aac791277f 100644 --- a/autoconf/configure.in +++ b/autoconf/configure.in @@ -394,8 +394,8 @@ AC_ARG_ENABLE(traymonitor, AC_HELP_STRING([--enable-traymonitor], [enable build of traymonitor @<:@default=no@:>@]), [ if test x$enableval = xyes; then - AC_DEFINE(HAVE_TRAYMONITOR, 1, [Define to 1 if tray-monitor Qt4 GUI support should be enabled]) - support_traymonitor=yes + AC_DEFINE(HAVE_TRAYMONITOR, 1, [Define to 1 if tray-monitor Qt4 GUI support should be enabled]) + support_traymonitor=yes fi ] ) @@ -405,7 +405,7 @@ if test x$support_traymonitor = xyes; then abc=`$PKGCONFIG --atleast-version=4.6 QtGui` pkg=$? if test $pkg = 0; then - TRAY_MONITOR_DIR=src/qt-console/tray-monitor + TRAY_MONITOR_DIR=src/qt-tray-monitor else AC_MSG_ERROR(Unable to find suitable Qt4 installation needed by tray-monitor) fi @@ -3536,9 +3536,9 @@ AC_OUTPUT([autoconf/Make.common \ src/include/host.h \ src/console/Makefile \ src/console/bconsole.conf \ - src/qt-console/tray-monitor/bareos-tray-monitor.desktop \ - src/qt-console/tray-monitor/tray-monitor.conf \ - src/qt-console/tray-monitor/tray-monitor.pro \ + src/qt-tray-monitor/bareos-tray-monitor.desktop \ + src/qt-tray-monitor/tray-monitor.conf \ + src/qt-tray-monitor/tray-monitor.pro \ src/qt-console/bat.conf \ src/qt-console/bat.desktop \ src/qt-console/bat.pro \ @@ -3614,7 +3614,7 @@ if test "${support_traymonitor}" = "yes" ; then AC_MSG_ERROR([Could not find qmake $PATH. Check your Qt installation]) fi - cd src/qt-console/tray-monitor + cd src/qt-tray-monitor echo "Creating tray-monitor Makefile" # hack: required to get "make install" to work touch bareos-tray-monitor diff --git a/platforms/win32/tray-monitor-conf.patch b/platforms/win32/tray-monitor-conf.patch index 971d3ed1b0e..d14e34ab883 100644 --- a/platforms/win32/tray-monitor-conf.patch +++ b/platforms/win32/tray-monitor-conf.patch @@ -1,6 +1,6 @@ -diff -ruN bareos-12.11.orig/src/qt-console/tray-monitor/tray-monitor.conf.in bareos-12.11/src/qt-console/tray-monitor/tray-monitor.conf.in ---- bareos-12.11.orig/src/qt-console/tray-monitor/tray-monitor.conf.in 2012-11-12 11:28:21.000000000 +0100 -+++ bareos-12.11/src/qt-console/tray-monitor/tray-monitor.conf.in 2012-11-17 00:59:17.000000000 +0100 +diff -ruN bareos-12.11.orig/src/qt-tray-monitor/tray-monitor.conf.in bareos-12.11/src/qt-tray-monitor/tray-monitor.conf.in +--- bareos-12.11.orig/src/qt-tray-monitor/tray-monitor.conf.in 2012-11-12 11:28:21.000000000 +0100 ++++ bareos-12.11/src/qt-tray-monitor/tray-monitor.conf.in 2012-11-17 00:59:17.000000000 +0100 @@ -15,15 +15,15 @@ Password = "@mon_fd_password@" # password for FileDaemon } diff --git a/platforms/win32/winbareos-nsi.spec b/platforms/win32/winbareos-nsi.spec index cf923e00aae..2d912c7a2fb 100644 --- a/platforms/win32/winbareos-nsi.spec +++ b/platforms/win32/winbareos-nsi.spec @@ -38,6 +38,7 @@ Source1: winbareos.nsi Source2: clientdialog.ini Source3: directordialog.ini Source4: KillProcWMI.dll +Source5: bareos.ico %description bareos @@ -83,11 +84,8 @@ for cfg in /etc/mingw64-winbareos/*.conf; do cp $cfg $RPM_BUILD_ROOT/release64 done -find / | grep LICENSE - -cp %SOURCE1 %SOURCE2 %SOURCE3 %SOURCE4 %_sourcedir/LICENSE $RPM_BUILD_ROOT/release32 -cp %SOURCE1 %SOURCE2 %SOURCE3 %SOURCE4 %_sourcedir/LICENSE $RPM_BUILD_ROOT/release64 - +cp %SOURCE1 %SOURCE2 %SOURCE3 %SOURCE4 %SOURCE5 %_sourcedir/LICENSE $RPM_BUILD_ROOT/release32 +cp %SOURCE1 %SOURCE2 %SOURCE3 %SOURCE4 %SOURCE5 %_sourcedir/LICENSE $RPM_BUILD_ROOT/release64 makensis -DPRODUCT_VERSION=%version-%release -DBIT_WIDTH=32 $RPM_BUILD_ROOT/release32/winbareos.nsi makensis -DPRODUCT_VERSION=%version-%release -DBIT_WIDTH=64 $RPM_BUILD_ROOT/release64/winbareos.nsi diff --git a/platforms/win32/winbareos.nsi b/platforms/win32/winbareos.nsi index 733019ead20..b21e46282cc 100644 --- a/platforms/win32/winbareos.nsi +++ b/platforms/win32/winbareos.nsi @@ -84,8 +84,10 @@ ${StrTrimNewLines} ; MUI Settings !define MUI_ABORTWARNING -!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico" -!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico" +!define MUI_ICON "bareos.ico" +!define MUI_UNICON "bareos.ico" +#!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico" +#!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico" !insertmacro GetParameters !insertmacro GetOptions @@ -313,30 +315,33 @@ SectionIn 2 SectionEnd -#Section /o "Tray-Monitor" SEC_TRAYMON -#SectionIn 1 2 -# -# -# SetShellVarContext all -# CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\bareos-tray-monitor.lnk" "$INSTDIR\bareos-tray-monitor.exe" '-c "$APPDATA\${PRODUCT_NAME}\tray-monitor.conf"' -# -# File "bareos-tray-monitor.exe" -## File "libbareos.dll" -## File "libcrypto-8.dll" -## File "libgcc_s_*-1.dll" -# File "libpng15-15.dll" -## File "libssl-8.dll" -## File "libstdc++-6.dll" -## File "pthreadGCE2.dll" -# File "QtCore4.dll" -# File "QtGui4.dll" -## File "zlib1.dll" -# -# -# !insertmacro InstallConfFile "tray-monitor.conf" -## File "tray-monitor.conf" -# -#SectionEnd +Section /o "Tray-Monitor" SEC_TRAYMON +SectionIn 1 2 + + + SetShellVarContext all + CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\bareos-tray-monitor.lnk" "$INSTDIR\bareos-tray-monitor.exe" '-c "$APPDATA\${PRODUCT_NAME}\tray-monitor.conf"' + +# autostart + CreateShortCut "$SMSTARTUP\bareos-tray-monitor.lnk" "$INSTDIR\bareos-tray-monitor.exe" '-c "$APPDATA\${PRODUCT_NAME}\tray-monitor.conf"' + + File "bareos-tray-monitor.exe" +# File "libbareos.dll" +# File "libcrypto-8.dll" +# File "libgcc_s_*-1.dll" + File "libpng15-15.dll" +# File "libssl-8.dll" +# File "libstdc++-6.dll" +# File "pthreadGCE2.dll" + File "QtCore4.dll" + File "QtGui4.dll" +# File "zlib1.dll" + + + !insertmacro InstallConfFile "tray-monitor.conf" +# File "tray-monitor.conf" + +SectionEnd Section /o "Qt Console (BAT)" SEC_BAT @@ -387,7 +392,7 @@ SectionEnd !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN !insertmacro MUI_DESCRIPTION_TEXT ${SEC_CLIENT} "Installs the Bareos File Daemon and required Files" !insertmacro MUI_DESCRIPTION_TEXT ${SEC_BCONSOLE} "Installs the CLI client console (bconsole)" -# !insertmacro MUI_DESCRIPTION_TEXT ${SEC_TRAYMON} "Installs the tray Icon to monitor the Bareos client" + !insertmacro MUI_DESCRIPTION_TEXT ${SEC_TRAYMON} "Installs the tray Icon to monitor the Bareos client" !insertmacro MUI_DESCRIPTION_TEXT ${SEC_BAT} "Installs the Qt Console (BAT)" !insertmacro MUI_DESCRIPTION_TEXT ${SEC_FIREWALL} "Opens Port 9102/TCP for bareos-fd.exe (Client program) in the Windows Firewall" !insertmacro MUI_FUNCTION_DESCRIPTION_END @@ -423,9 +428,11 @@ SectionEnd Section -StartDaemon nsExec::ExecToLog "net start bareos-fd" + ${If} ${SectionIsSelected} ${SEC_TRAYMON} + MessageBox MB_OK|MB_ICONINFORMATION "The tray monitor will be started automatically on next login" /SD IDOK + ${EndIf} SectionEnd - # helper functions to find out computer name Function GetComputerName Push $R0 @@ -588,7 +595,7 @@ Function .onInit # make first section mandatory SectionSetFlags ${SEC_CLIENT} 17 # SF_SELECTED & SF_RO # SectionSetFlags ${SEC_BCONSOLE} ${SF_SELECTED} # SF_SELECTED -#SectionSetFlags ${SEC_TRAYMON} ${SF_SELECTED} # SF_SELECTED +SectionSetFlags ${SEC_TRAYMON} ${SF_SELECTED} # SF_SELECTED # find out the computer name Call GetComputerName @@ -770,6 +777,12 @@ Section Uninstall nsExec::ExecToLog '"$INSTDIR\bareos-fd.exe" /remove' +# KillProcWMI::KillProc "bareos-fd.exe" +# kill tray monitor + KillProcWMI::KillProc "bareos-tray-monitor.exe" + + + # ask if existing config files should be kept IfSilent +2 MessageBox MB_YESNO|MB_ICONQUESTION \ @@ -825,6 +838,11 @@ ConfDeleteSkip: Delete "$SMPROGRAMS\${PRODUCT_NAME}\bconsole.lnk" Delete "$SMPROGRAMS\${PRODUCT_NAME}\BAT.lnk" Delete "$DESKTOP\BAT.lnk" +# traymon + Delete "$SMPROGRAMS\${PRODUCT_NAME}\bareos-tray-monitor.lnk" +# traymon autostart + Delete "$SMSTARTUP\bareos-tray-monitor.lnk" + Delete "$SMPROGRAMS\${PRODUCT_NAME}\Website.lnk" Delete "$SMPROGRAMS\${PRODUCT_NAME}\Uninstall.lnk" RMDir "$SMPROGRAMS\${PRODUCT_NAME}" diff --git a/platforms/win32/winbareos32.spec b/platforms/win32/winbareos32.spec index f31c3ccca07..f7b28877ae9 100644 --- a/platforms/win32/winbareos32.spec +++ b/platforms/win32/winbareos32.spec @@ -104,7 +104,7 @@ cp qt-tray-monitor/bareos-tray-monitor.exe \ findlib/libbareosfind.dll \ plugins/fd/bpipe-fd.dll $RPM_BUILD_ROOT%{_mingw32_bindir} -for cfg in ../qt-console/tray-monitor/tray-monitor.conf.in \ +for cfg in ../qt-tray-monitor/tray-monitor.conf.in \ ../qt-console/bat.conf.in \ ../filed/bareos-fd.conf.in \ ../console/bconsole.conf.in \ diff --git a/platforms/win32/winbareos64.spec b/platforms/win32/winbareos64.spec index 698cd26b5fa..2774b3b317e 100644 --- a/platforms/win32/winbareos64.spec +++ b/platforms/win32/winbareos64.spec @@ -105,7 +105,7 @@ cp qt-tray-monitor/bareos-tray-monitor.exe \ findlib/libbareosfind.dll \ plugins/fd/bpipe-fd.dll $RPM_BUILD_ROOT%{_mingw64_bindir} -for cfg in ../qt-console/tray-monitor/tray-monitor.conf.in \ +for cfg in ../qt-tray-monitor/tray-monitor.conf.in \ ../qt-console/bat.conf.in \ ../filed/bareos-fd.conf.in \ ../console/bconsole.conf.in \ diff --git a/src/console/console.c b/src/console/console.c index 4774413fc3b..a8d5db59002 100644 --- a/src/console/console.c +++ b/src/console/console.c @@ -946,7 +946,7 @@ static bool select_director(const char *director, DIRRES **ret_dir, CONRES **ret if (get_cmd(stdin, _("Select Director by entering a number: "), UA_sock, 600) < 0) { - (void)WSACleanup(); /* Cleanup Windows sockets */ + WSACleanup(); /* Cleanup Windows sockets */ return 0; } if (!is_a_number(UA_sock->msg)) { @@ -1268,7 +1268,7 @@ static void terminate_console(int sig) if (!no_conio) { con_term(); } - (void)WSACleanup(); /* Cleanup Windows sockets */ + WSACleanup(); /* Cleanup Windows sockets */ lmgr_cleanup_main(); if (sig != 0) { diff --git a/src/qt-console/images/applications-graphics.svg b/src/images/applications-graphics.svg similarity index 100% rename from src/qt-console/images/applications-graphics.svg rename to src/images/applications-graphics.svg diff --git a/src/images/bat.svg b/src/images/bat.svg new file mode 100644 index 00000000000..7c866e6db82 --- /dev/null +++ b/src/images/bat.svg @@ -0,0 +1,78 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + diff --git a/src/qt-console/images/browse.svg b/src/images/browse.svg similarity index 100% rename from src/qt-console/images/browse.svg rename to src/images/browse.svg diff --git a/src/qt-console/images/cartridge-edit.svg b/src/images/cartridge-edit.svg similarity index 100% rename from src/qt-console/images/cartridge-edit.svg rename to src/images/cartridge-edit.svg diff --git a/src/qt-console/images/cartridge.svg b/src/images/cartridge.svg similarity index 100% rename from src/qt-console/images/cartridge.svg rename to src/images/cartridge.svg diff --git a/src/qt-console/images/check.svg b/src/images/check.svg similarity index 100% rename from src/qt-console/images/check.svg rename to src/images/check.svg diff --git a/src/qt-console/images/edit-delete.svg b/src/images/edit-delete.svg similarity index 100% rename from src/qt-console/images/edit-delete.svg rename to src/images/edit-delete.svg diff --git a/src/qt-console/images/emblem-system.svg b/src/images/emblem-system.svg similarity index 100% rename from src/qt-console/images/emblem-system.svg rename to src/images/emblem-system.svg diff --git a/src/qt-console/images/estimate-job.svg b/src/images/estimate-job.svg similarity index 100% rename from src/qt-console/images/estimate-job.svg rename to src/images/estimate-job.svg diff --git a/src/qt-console/images/folder.svg b/src/images/folder.svg similarity index 100% rename from src/qt-console/images/folder.svg rename to src/images/folder.svg diff --git a/src/qt-console/images/folderbothchecked.svg b/src/images/folderbothchecked.svg similarity index 100% rename from src/qt-console/images/folderbothchecked.svg rename to src/images/folderbothchecked.svg diff --git a/src/qt-console/images/folderchecked.svg b/src/images/folderchecked.svg similarity index 100% rename from src/qt-console/images/folderchecked.svg rename to src/images/folderchecked.svg diff --git a/src/qt-console/images/folderunchecked.svg b/src/images/folderunchecked.svg similarity index 100% rename from src/qt-console/images/folderunchecked.svg rename to src/images/folderunchecked.svg diff --git a/src/qt-console/images/go-down.svg b/src/images/go-down.svg similarity index 100% rename from src/qt-console/images/go-down.svg rename to src/images/go-down.svg diff --git a/src/qt-console/images/go-jump.svg b/src/images/go-jump.svg similarity index 100% rename from src/qt-console/images/go-jump.svg rename to src/images/go-jump.svg diff --git a/src/qt-console/images/go-up.svg b/src/images/go-up.svg similarity index 100% rename from src/qt-console/images/go-up.svg rename to src/images/go-up.svg diff --git a/src/qt-console/images/graph1.svg b/src/images/graph1.svg similarity index 100% rename from src/qt-console/images/graph1.svg rename to src/images/graph1.svg diff --git a/src/qt-console/images/help-browser.svg b/src/images/help-browser.svg similarity index 100% rename from src/qt-console/images/help-browser.svg rename to src/images/help-browser.svg diff --git a/src/qt-console/images/joblog.svg b/src/images/joblog.svg similarity index 100% rename from src/qt-console/images/joblog.svg rename to src/images/joblog.svg diff --git a/src/qt-console/images/mail-message-new.svg b/src/images/mail-message-new.svg similarity index 100% rename from src/qt-console/images/mail-message-new.svg rename to src/images/mail-message-new.svg diff --git a/src/qt-console/images/mail-message-pending.svg b/src/images/mail-message-pending.svg similarity index 100% rename from src/qt-console/images/mail-message-pending.svg rename to src/images/mail-message-pending.svg diff --git a/src/qt-console/images/media-floppy.svg b/src/images/media-floppy.svg similarity index 100% rename from src/qt-console/images/media-floppy.svg rename to src/images/media-floppy.svg diff --git a/src/qt-console/images/network-server.svg b/src/images/network-server.svg similarity index 100% rename from src/qt-console/images/network-server.svg rename to src/images/network-server.svg diff --git a/src/qt-console/images/package-x-generic.svg b/src/images/package-x-generic.svg similarity index 100% rename from src/qt-console/images/package-x-generic.svg rename to src/images/package-x-generic.svg diff --git a/src/qt-console/images/status-console.svg b/src/images/status-console.svg similarity index 100% rename from src/qt-console/images/status-console.svg rename to src/images/status-console.svg diff --git a/src/qt-console/images/status.svg b/src/images/status.svg similarity index 100% rename from src/qt-console/images/status.svg rename to src/images/status.svg diff --git a/src/qt-console/images/system-file-manager.svg b/src/images/system-file-manager.svg similarity index 100% rename from src/qt-console/images/system-file-manager.svg rename to src/images/system-file-manager.svg diff --git a/src/qt-console/images/unchecked.svg b/src/images/unchecked.svg similarity index 100% rename from src/qt-console/images/unchecked.svg rename to src/images/unchecked.svg diff --git a/src/qt-console/images/utilities-terminal.svg b/src/images/utilities-terminal.svg similarity index 100% rename from src/qt-console/images/utilities-terminal.svg rename to src/images/utilities-terminal.svg diff --git a/src/qt-console/images/view-refresh.svg b/src/images/view-refresh.svg similarity index 100% rename from src/qt-console/images/view-refresh.svg rename to src/images/view-refresh.svg diff --git a/src/qt-console/images/weather-severe-alert.svg b/src/images/weather-severe-alert.svg similarity index 100% rename from src/qt-console/images/weather-severe-alert.svg rename to src/images/weather-severe-alert.svg diff --git a/src/include/baconfig.h b/src/include/baconfig.h index 4b953d3aaa4..25d62bdc2cc 100644 --- a/src/include/baconfig.h +++ b/src/include/baconfig.h @@ -661,10 +661,10 @@ extern void pause_msg(const char *file, const char *func, int line, const char * * Unix/Linix */ #define PathSeparator '/' -/* Define Winsock functions if we aren't on Windows */ -#define WSA_Init() 0 /* 0 = success */ -#define WSACleanup() 0 /* 0 = success */ +/* Define Winsock functions if we aren't on Windows */ +inline int WSA_Init() { return (0); } /* 0 = success */ +inline int WSACleanup() { return (0); } /* 0 = success */ inline bool IsPathSeparator(int ch) { return ch == '/'; } inline char *first_path_separator(char *path) { return strchr(path, '/'); } diff --git a/src/qt-console/bat.pro.in b/src/qt-console/bat.pro.in index b3eb53f89f2..958df7eb555 100644 --- a/src/qt-console/bat.pro.in +++ b/src/qt-console/bat.pro.in @@ -20,9 +20,9 @@ bins.files = bat confs.path = /$(DESTDIR)@sysconfdir@ confs.commands = ./install_conf_file help.path = /$(DESTDIR)@htmldir@ -help.files = help/*.html images/status.png images/mail-message-new.png +help.files = help/*.html ../images/status.png ../images/mail-message-new.png icons.path = /$(DESTDIR)@datarootdir@/pixmaps/ -icons.files = images/bat.png images/bat.svg +icons.files = ../images/bat.png ../images/bat.svg desktopentries.path = /$(DESTDIR)@datarootdir@/applications/ desktopentries.files = bat.desktop @@ -31,7 +31,7 @@ TEMPLATE = app TARGET = bat DEPENDPATH += . INCLUDEPATH += .. ../include . -LIBS += -L../lib -lbareoscfg -lbareos -L../findlib -lbareosfind @OPENSSL_LIBS@ +LIBS += -L../lib -lbareoscfg -lbareos LIBTOOL_LINK = @QMAKE_LIBTOOL@ --silent --tag=CXX --mode=link LIBTOOL_INSTALL = @QMAKE_LIBTOOL@ --silent --mode=install QMAKE_LINK = $${LIBTOOL_LINK} $(CXX) @@ -39,7 +39,7 @@ QMAKE_INSTALL_PROGRAM = $${LIBTOOL_INSTALL} install -m @SBINPERM@ -p QMAKE_CLEAN += .libs/* bat macx { - ICON = images/bat.icns + ICON = ../images/bat.icns } RESOURCES = main.qrc diff --git a/src/qt-console/main.qrc b/src/qt-console/main.qrc index 60f01d969a2..69e9df38bdb 100644 --- a/src/qt-console/main.qrc +++ b/src/qt-console/main.qrc @@ -1,75 +1,77 @@ - - images/page-prev.gif - images/page-next.gif - images/0p.png - images/16p.png - images/32p.png - images/48p.png - images/64p.png - images/80p.png - images/96p.png - images/A.png - images/R.png - images/T.png - images/W.png - images/applications-graphics.png - images/bat.png - images/bat.svg - images/browse.png - images/cartridge-edit.png - images/cartridge.png - images/check.png - images/connected.png - images/copy.png - images/cut.png - images/disconnected.png - images/edit-cut.png - images/edit-delete.png - images/edit.png - images/emblem-system.png - images/estimate-job.png - images/extern.png - images/f.png - images/folder.png - images/folderbothchecked.png - images/folderchecked.png - images/folderunchecked.png - images/go-down.png - images/go-jump.png - images/go-up.png - images/graph1.png - images/help-browser.png - images/inflag0.png - images/inflag1.png - images/inflag2.png - images/intern.png - images/joblog.png - images/label.png - images/mail-message-new.png - images/mail-message-pending.png - images/mark.png - images/network-server.png - images/new.png - images/open.png - images/package-x-generic.png - images/paste.png - images/print.png - images/purge.png - images/restore.png - images/run.png - images/runit.png - images/save.png - images/status-console.png - images/status.png - images/system-file-manager.png - images/unchecked.png - images/undo.png - images/unmark.png - images/up.png - images/utilities-terminal.png - images/view-refresh.png - images/weather-severe-alert.png - images/zoom.png - + + ../images/page-prev.gif + ../images/page-next.gif + ../images/0p.png + ../images/16p.png + ../images/32p.png + ../images/48p.png + ../images/64p.png + ../images/80p.png + ../images/96p.png + ../images/A.png + ../images/R.png + ../images/T.png + ../images/W.png + ../images/applications-graphics.png + ../images/bat.png + ../images/bat.svg + ../images/browse.png + ../images/cartridge-edit.png + ../images/cartridge.png + ../images/check.png + ../images/connected.png + ../images/copy.png + ../images/cut.png + ../images/disconnected.png + ../images/edit-cut.png + ../images/edit-delete.png + ../images/edit.png + ../images/emblem-system.png + ../images/estimate-job.png + ../images/extern.png + ../images/f.png + ../images/folder.png + ../images/folderbothchecked.png + ../images/folderchecked.png + ../images/folderunchecked.png + ../images/go-down.png + ../images/go-jump.png + ../images/go-up.png + ../images/graph1.png + ../images/help-browser.png + ../images/inflag0.png + ../images/inflag1.png + ../images/inflag2.png + ../images/intern.png + ../images/joblog.png + ../images/label.png + ../images/mail-message-new.png + ../images/mail-message-pending.png + ../images/mark.png + ../images/network-server.png + ../images/new.png + ../images/open.png + ../images/package-x-generic.png + ../images/paste.png + ../images/print.png + ../images/purge.png + ../images/restore.png + ../images/run.png + ../images/runit.png + ../images/save.png + ../images/status-console.png + ../images/status.png + ../images/system-file-manager.png + ../images/unchecked.png + ../images/undo.png + ../images/unmark.png + ../images/up.png + ../images/utilities-terminal.png + ../images/view-refresh.png + ../images/weather-severe-alert.png + ../images/zoom.png + ../images/bareos_1.png + ../images/bareos_2.png + diff --git a/src/qt-console/mainwin.cpp b/src/qt-console/mainwin.cpp index 12c46d897b3..805ab605c29 100644 --- a/src/qt-console/mainwin.cpp +++ b/src/qt-console/mainwin.cpp @@ -597,15 +597,16 @@ void MainWin::input_line() void MainWin::about() { - QMessageBox::about(this, tr("About Bareos Administration Tool"), - tr("

Bareos Administration Tool %1

" - "

Original by Dirk H Bartley and Kern Sibbald

" - "

For more information, see: www.bareos.com

" - "

Copyright © 2007-%2 Free Software Foundation Europe e.V.

" - "

Copyright © 2011-2012 Planets Communications B.V.

" - "

Copyright © 2013-%2 Bareos GmbH & Co. KG

" - "

BAREOS® is a registered trademark of Bareos GmbH & Co. KG

" - "

Licensed under GNU AGPLv3.

").arg(VERSION).arg(BYEAR)); + QString fmt = QString("

Bareos Administration Tool %1

" + "

Original by Dirk H Bartley and Kern Sibbald

" + "

For more information, see: www.bareos.com" + "

Copyright © 2007-2010 Free Software Foundation Europe e.V." + "

Copyright © 2011-2012 Planets Communications B.V." + "

Copyright © 2013-%2 Bareos GmbH & Co. KG" + "

BAREOS ® is a registered trademark of Bareos GmbH & Co. KG" + "

Licensed under GNU AGPLv3.").arg(VERSION).arg(BYEAR); + + QMessageBox::about(this, tr("About Bareos Administration Tool"), fmt); } void MainWin::help() diff --git a/src/qt-console/tray-monitor/tray-monitor.cpp b/src/qt-console/tray-monitor/tray-monitor.cpp deleted file mode 100644 index 210366f9e24..00000000000 --- a/src/qt-console/tray-monitor/tray-monitor.cpp +++ /dev/null @@ -1,465 +0,0 @@ -/* - BAREOS® - Backup Archiving REcovery Open Sourced - - Copyright (C) 2004-2011 Free Software Foundation Europe e.V. - - This program is Free Software; you can redistribute it and/or - modify it under the terms of version three of the GNU Affero General Public - License as published by the Free Software Foundation and included - in the file LICENSE. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "tray-ui.h" - -int doconnect(monitoritem* item); -int docmd(monitoritem* item, const char* command); -static int authenticate_daemon(monitoritem* item, JCR *jcr); -/* Imported functions */ -int authenticate_director(JCR *jcr, MONITORRES *monitor, DIRRES *director); -int authenticate_file_daemon(JCR *jcr, MONITORRES *monitor, CLIENTRES* client); -int authenticate_storage_daemon(JCR *jcr, MONITORRES *monitor, STORERES* store); -extern bool parse_tmon_config(CONFIG *config, const char *configfile, int exit_code); -void get_list(monitoritem* item, const char *cmd, QStringList &lst); - -/* Dummy functions */ -int generate_daemon_event(JCR *, const char *) { return 1; } - -/* Static variables */ -static char *configfile = NULL; -static MONITORRES *monitor; -static JCR jcr; -static int nitems = 0; -static monitoritem items[32]; -static CONFIG *config; -static TrayUI *tray; - -/* Data received from DIR/FD/SD */ -//static char OKqstatus[] = "%c000 OK .status\n"; -//static char DotStatusJob[] = "JobId=%d JobStatus=%c JobErrors=%d\n"; - - -void updateStatusIcon(monitoritem* item); -void changeStatusMessage(monitoritem* item, const char *fmt,...); - -#define CONFIG_FILE "tray-monitor.conf" /* default configuration file */ - -static void usage() -{ - fprintf(stderr, _( -PROG_COPYRIGHT -"\nVersion: %s (%s) %s %s %s\n\n" -"Usage: tray-monitor [-c config_file] [-d debug_level]\n" -" -c set configuration file to file\n" -" -d set debug level to \n" -" -dt print timestamp in debug output\n" -" -t test - read configuration and exit\n" -" -? print this message.\n" -"\n"), 2004, VERSION, BDATE, HOST_OS, DISTNAME, DISTVER); -} - -int sm_line = 0; - -void dotest() -{ - for (int i = 0; i < nitems; i++) { - const char *cmd; - - switch (items[i].type) { - case R_DIRECTOR: - cmd = ".jobs type=B"; - tray->clearText(items[i].get_name()); - docmd(&items[i], cmd); - break; - default: - break; - } - } -} - -void get_list(monitoritem *item, const char *cmd, QStringList &lst) -{ - int stat; - - doconnect(item); - item->writecmd(cmd); - while((stat = bnet_recv(item->D_sock)) >= 0) { - strip_trailing_newline(item->D_sock->msg); - if (*(item->D_sock->msg)) { - lst << QString(item->D_sock->msg); - } - } -} - -void refresh_item() -{ - for (int i = 0; i < nitems; i++) { - const char *cmd; - tray->clearText(items[i].get_name()); - switch (items[i].type) { - case R_DIRECTOR: - cmd = "status dir"; - break; - case R_CLIENT: - cmd = "status"; - break; - case R_STORAGE: - cmd = "status"; - break; - default: - exit(1); - break; - } - docmd(&items[i], cmd); - } -} - -/********************************************************************* - * - * Main Bareos Tray Monitor -- User Interface Program - * - */ -int main(int argc, char *argv[]) -{ - int ch, i, dir_index=-1; - bool test_config = false; - DIRRES* dird; - CLIENTRES* filed; - STORERES* stored; - - setlocale(LC_ALL, ""); - bindtextdomain("bareos", LOCALEDIR); - textdomain("bareos"); - - init_stack_dump(); - my_name_is(argc, argv, "tray-monitor"); - lmgr_init_thread(); - init_msg(NULL, NULL); - working_directory = "/tmp"; - - struct sigaction sigignore; - sigignore.sa_flags = 0; - sigignore.sa_handler = SIG_IGN; - sigfillset(&sigignore.sa_mask); - sigaction(SIGPIPE, &sigignore, NULL); - - while ((ch = getopt(argc, argv, "bc:d:th?f:s:")) != -1) { - switch (ch) { - case 'c': /* configuration file */ - if (configfile != NULL) { - free(configfile); - } - configfile = bstrdup(optarg); - break; - - case 'd': - if (*optarg == 't') { - dbg_timestamp = true; - } else { - debug_level = atoi(optarg); - if (debug_level <= 0) { - debug_level = 1; - } - } - break; - - case 't': - test_config = true; - break; - - case 'h': - case '?': - default: - usage(); - exit(1); - } - } - argc -= optind; - //argv += optind; - - if (argc) { - usage(); - exit(1); - } - - if (configfile == NULL) { - configfile = bstrdup(CONFIG_FILE); - } - - config = new_config_parser(); - parse_tmon_config(config, configfile, M_ERROR_TERM); - - LockRes(); - nitems = 0; - foreach_res(monitor, R_MONITOR) { - nitems++; - } - - if (nitems != 1) { - Emsg2(M_ERROR_TERM, 0, - _("Error: %d Monitor resources defined in %s. You must define one and only one Monitor resource.\n"), nitems, configfile); - } - - nitems = 0; - foreach_res(dird, R_DIRECTOR) { - dir_index=nitems; - items[nitems].type = R_DIRECTOR; - items[nitems].resource = dird; - items[nitems].D_sock = NULL; - items[nitems].state = warn; - items[nitems].oldstate = warn; - nitems++; - } - foreach_res(filed, R_CLIENT) { - items[nitems].type = R_CLIENT; - items[nitems].resource = filed; - items[nitems].D_sock = NULL; - items[nitems].state = warn; - items[nitems].oldstate = warn; - nitems++; - } - foreach_res(stored, R_STORAGE) { - items[nitems].type = R_STORAGE; - items[nitems].resource = stored; - items[nitems].D_sock = NULL; - items[nitems].state = warn; - items[nitems].oldstate = warn; - nitems++; - } - UnlockRes(); - - if (nitems == 0) { - Emsg1(M_ERROR_TERM, 0, _("No Client, Storage or Director resource defined in %s\n" -"Without that I don't how to get status from the File, Storage or Director Daemon :-(\n"), configfile); - } - - if (test_config) { - exit(0); - } - - (void)WSA_Init(); /* Initialize Windows sockets */ - - LockRes(); - monitor = (MONITORRES*)GetNextRes(R_MONITOR, (RES *)NULL); - UnlockRes(); - - if ((monitor->RefreshInterval < 1) || (monitor->RefreshInterval > 600)) { - Emsg2(M_ERROR_TERM, 0, _("Invalid refresh interval defined in %s\n" -"This value must be greater or equal to 1 second and less or equal to 10 minutes (read value: %d).\n"), configfile, monitor->RefreshInterval); - } - - sm_line = 0; - QApplication app(argc, argv); - app.setQuitOnLastWindowClosed(false); - tray = new TrayUI(); - tray->setupUi(tray); - tray->spinRefresh->setValue(monitor->RefreshInterval); - if (dir_index >= 0) { - tray->addDirector(&items[dir_index]); - } - - for (i = 0; i < nitems; i++) { - const char *cmd; - tray->addTab(items[i].get_name()); - switch (items[i].type) { - case R_DIRECTOR: - tray->addDirector(&items[i]); - cmd = "status dir"; - break; - case R_CLIENT: - cmd = "status"; - break; - case R_STORAGE: - cmd = "status"; - break; - default: - exit(1); - break; - } - docmd(&items[i], cmd); - } - - tray->startTimer(); - - app.exec(); - - for (i = 0; i < nitems; i++) { - if (items[i].D_sock) { - items[i].writecmd("quit"); - if (items[i].D_sock) { - items[i].D_sock->signal(BNET_TERMINATE); /* send EOF */ - items[i].D_sock->close(); - items[i].D_sock = NULL; - } - } - } - - - (void)WSACleanup(); /* Cleanup Windows sockets */ - - config->free_resources(); - free(config); - config = NULL; - term_msg(); - return 0; -} - -static int authenticate_daemon(monitoritem* item, JCR *jcr) { - switch (item->type) { - case R_DIRECTOR: - return authenticate_director(jcr, monitor, (DIRRES*)item->resource); - case R_CLIENT: - return authenticate_file_daemon(jcr, monitor, (CLIENTRES*)item->resource); - case R_STORAGE: - return authenticate_storage_daemon(jcr, monitor, (STORERES*)item->resource); - default: - printf(_("Error, currentitem is not a Client or a Storage..\n")); - return FALSE; - } - return false; -} - -void changeStatusMessage(monitoritem*, const char *fmt,...) { - char buf[512]; - va_list arg_ptr; - - va_start(arg_ptr, fmt); - bvsnprintf(buf, sizeof(buf), (char *)fmt, arg_ptr); - va_end(arg_ptr); - tray->statusbar->showMessage(QString(buf)); -} - -int doconnect(monitoritem* item) -{ - if (!item->D_sock) { - memset(&jcr, 0, sizeof(jcr)); - - DIRRES* dird; - CLIENTRES* filed; - STORERES* stored; - - switch (item->type) { - case R_DIRECTOR: - dird = (DIRRES*)item->resource; - changeStatusMessage(item, _("Connecting to Director %s:%d"), dird->address, dird->DIRport); - item->D_sock = bnet_connect(NULL, monitor->DIRConnectTimeout, - 0, 0, _("Director daemon"), dird->address, NULL, dird->DIRport, 0); - jcr.dir_bsock = item->D_sock; - break; - case R_CLIENT: - filed = (CLIENTRES*)item->resource; - changeStatusMessage(item, _("Connecting to Client %s:%d"), filed->address, filed->FDport); - item->D_sock = bnet_connect(NULL, monitor->FDConnectTimeout, - 0, 0, _("File daemon"), filed->address, NULL, filed->FDport, 0); - jcr.file_bsock = item->D_sock; - break; - case R_STORAGE: - stored = (STORERES*)item->resource; - changeStatusMessage(item, _("Connecting to Storage %s:%d"), stored->address, stored->SDport); - item->D_sock = bnet_connect(NULL, monitor->SDConnectTimeout, - 0, 0, _("Storage daemon"), stored->address, NULL, stored->SDport, 0); - jcr.store_bsock = item->D_sock; - break; - default: - printf(_("Error, currentitem is not a Client, a Storage or a Director..\n")); - return 0; - } - - if (item->D_sock == NULL) { - changeStatusMessage(item, _("Cannot connect to daemon.")); - item->state = error; - item->oldstate = error; - return 0; - } - - if (!authenticate_daemon(item, &jcr)) { - item->state = error; - item->oldstate = error; - changeStatusMessage(item, _("Authentication error : %s"), item->D_sock->msg); - item->D_sock = NULL; - return 0; - } - - switch (item->type) { - case R_DIRECTOR: - changeStatusMessage(item, _("Opened connection with Director daemon.")); - break; - case R_CLIENT: - changeStatusMessage(item, _("Opened connection with File daemon.")); - break; - case R_STORAGE: - changeStatusMessage(item, _("Opened connection with Storage daemon.")); - break; - default: - printf(_("Error, currentitem is not a Client, a Storage or a Director..\n")); - return 0; - break; - } - - if (item->type == R_DIRECTOR) { /* Read connection messages... */ - docmd(item, ""); /* Usually invalid, but no matter */ - } - } - return 1; -} - -int docmd(monitoritem* item, const char* command) -{ - int stat; - //qDebug() << "docmd(" << item->get_name() << "," << command << ")"; - if (!doconnect(item)) { - return 0; - } - - if (command[0] != 0) - item->writecmd(command); - - while(1) { - if ((stat = bnet_recv(item->D_sock)) >= 0) { - strip_trailing_newline(item->D_sock->msg); - tray->appendText(item->get_name(), item->D_sock->msg); - } - else if (stat == BNET_SIGNAL) { - if (item->D_sock->msglen == BNET_EOD) { - // qDebug() << "<< EOD >>"; - return 1; - } - else if (item->D_sock->msglen == BNET_SUB_PROMPT) { - // qDebug() << "<< PROMPT >>"; - return 0; - } - else if (item->D_sock->msglen == BNET_HEARTBEAT) { - bnet_sig(item->D_sock, BNET_HB_RESPONSE); - } - else { - qDebug() << bnet_sig_to_ascii(item->D_sock); - } - } - else { /* BNET_HARDEOF || BNET_ERROR */ - item->D_sock = NULL; - item->state = error; - item->oldstate = error; - changeStatusMessage(item, _("Error : BNET_HARDEOF or BNET_ERROR")); - //fprintf(stderr, _("<< ERROR >>\n")); - return 0; - } - - if (is_bnet_stop(item->D_sock)) { - item->D_sock = NULL; - item->state = error; - item->oldstate = error; - changeStatusMessage(item, _("Error : Connection closed.")); - //fprintf(stderr, "<< STOP >>\n"); - return 0; /* error or term */ - } - } -} diff --git a/src/qt-console/tray-monitor/tray-monitor.h b/src/qt-console/tray-monitor/tray-monitor.h deleted file mode 100644 index 929bc7fa4dd..00000000000 --- a/src/qt-console/tray-monitor/tray-monitor.h +++ /dev/null @@ -1,181 +0,0 @@ -/* - BAREOS® - Backup Archiving REcovery Open Sourced - - Copyright (C) 2004-2007 Free Software Foundation Europe e.V. - Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2013 Bareos GmbH & Co. KG - - This program is Free Software; you can redistribute it and/or - modify it under the terms of version three of the GNU Affero General Public - License as published by the Free Software Foundation and included - in the file LICENSE. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ -/* - * Includes specific to the tray monitor - * - * Nicolas Boichat, August MMIV - */ - -#ifndef TRAY_MONITOR_H -#define TRAY_MONITOR_H - -#ifdef HAVE_WIN32 -# ifndef _STAT_DEFINED -# define _STAT_DEFINED 1 /* don't pull in MinGW struct stat from wchar.h */ -# endif -#endif - -#include -#include - -#include "bareos.h" -#include "tray_conf.h" -#include "jcr.h" - - -struct job_defaults { - QString job_name; - QString pool_name; - QString messages_name; - QString client_name; - QString store_name; - QString where; - QString level; - QString type; - QString fileset_name; - QString catalog_name; - bool enabled; -}; - -struct resources { - QStringList job_list; - QStringList pool_list; - QStringList client_list; - QStringList storage_list; - QStringList levels; - QStringList fileset_list; - QStringList messages_list; -}; - -enum stateenum { - idle = 0, - running = 1, - warn = 2, - error = 3 -}; - -class monitoritem; -int doconnect(monitoritem* item); -void get_list(monitoritem* item, const char *cmd, QStringList &lst); - -class monitoritem { -public: - rescode type; /* R_DIRECTOR, R_CLIENT or R_STORAGE */ - void* resource; /* DIRRES*, CLIENTRES* or STORERES* */ - BSOCK *D_sock; - stateenum state; - stateenum oldstate; - - char *get_name() { - return ((URES*)resource)->hdr.name; - } - - void writecmd(const char* command) { - if (this->D_sock) { - this->D_sock->msglen = pm_strcpy(&this->D_sock->msg, command); - bnet_send(this->D_sock); - } - } - - bool get_job_defaults(struct job_defaults &job_defs) - { - int stat; - char *def; - BSOCK *dircomm; - bool rtn = false; - QString scmd = QString(".defaults job=\"%1\"").arg(job_defs.job_name); - - if (job_defs.job_name == "") { - return rtn; - } - - if (!doconnect(this)) { - return rtn; - } - dircomm = this->D_sock; - dircomm->fsend("%s", scmd.toUtf8().data()); - - while ((stat = dircomm->recv()) > 0) { - def = strchr(dircomm->msg, '='); - if (!def) { - continue; - } - /* Pointer to default value */ - *def++ = 0; - strip_trailing_newline(def); - - if (strcmp(dircomm->msg, "job") == 0) { - if (strcmp(def, job_defs.job_name.toUtf8().data()) != 0) { - goto bail_out; - } - continue; - } - if (strcmp(dircomm->msg, "pool") == 0) { - job_defs.pool_name = def; - continue; - } - if (strcmp(dircomm->msg, "messages") == 0) { - job_defs.messages_name = def; - continue; - } - if (strcmp(dircomm->msg, "client") == 0) { - job_defs.client_name = def; - continue; - } - if (strcmp(dircomm->msg, "storage") == 0) { - job_defs.store_name = def; - continue; - } - if (strcmp(dircomm->msg, "where") == 0) { - job_defs.where = def; - continue; - } - if (strcmp(dircomm->msg, "level") == 0) { - job_defs.level = def; - continue; - } - if (strcmp(dircomm->msg, "type") == 0) { - job_defs.type = def; - continue; - } - if (strcmp(dircomm->msg, "fileset") == 0) { - job_defs.fileset_name = def; - continue; - } - if (strcmp(dircomm->msg, "catalog") == 0) { - job_defs.catalog_name = def; - continue; - } - if (strcmp(dircomm->msg, "enabled") == 0) { - job_defs.enabled = *def == '1' ? true : false; - continue; - } - } - rtn = true; - /* Fall through wanted */ - bail_out: - return rtn; - } -}; - -#endif /* TRAY_MONITOR_H */ diff --git a/src/qt-console/tray-monitor/tray-ui.h b/src/qt-console/tray-monitor/tray-ui.h deleted file mode 100644 index 6dee593eb1e..00000000000 --- a/src/qt-console/tray-monitor/tray-ui.h +++ /dev/null @@ -1,392 +0,0 @@ -/* - BAREOS® - Backup Archiving REcovery Open Sourced - - Copyright (C) 2011-2011 Free Software Foundation Europe e.V. - - This program is Free Software; you can redistribute it and/or - modify it under the terms of version three of the GNU Affero General Public - License as published by the Free Software Foundation, which is - listed in the file LICENSE. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. - - BAREOS® is a registered trademark of Bareos GmbH & Co. KG -*/ - -#ifndef TRAYUI_H -#define TRAYUI_H - -#ifdef HAVE_WIN32 -# ifndef _STAT_DEFINED -# define _STAT_DEFINED 1 /* don't pull in MinGW struct stat from wchar.h */ -# endif -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "version.h" -#include "ui/ui_run.h" -#include "tray-monitor.h" - -class RunDlg: public QDialog, public Ui::runForm -{ - Q_OBJECT - -public: - monitoritem *item; - - void fill(QComboBox *cb, QStringList &lst) { - if (lst.length()) { - cb->addItems(lst); - } else { - cb->setEnabled(false); - } - } - RunDlg(monitoritem *i) { - struct resources res; - struct job_defaults jdefault; - QDateTime dt; - item = i; - - qDebug() << "start getting elements"; - get_list(item, ".jobs type=B", res.job_list); - - if (res.job_list.length() == 0) { - QMessageBox msgBox; - msgBox.setText("This restricted console doesn't have access to Backup jobs"); - msgBox.setIcon(QMessageBox::Warning); - msgBox.exec(); - this->deleteLater(); - return; - } - - get_list(item, ".pools", res.pool_list); - get_list(item, ".clients", res.client_list); - get_list(item, ".storage", res.storage_list); - res.levels << "Full" << "Incremental" << "Differential"; - get_list(item, ".filesets", res.fileset_list); - get_list(item, ".messages", res.messages_list); - - setupUi(this); - - qDebug() << " -> done"; - label_5->setVisible(false); - bootstrap->setVisible(false); - jobCombo->addItems(res.job_list); - fill(filesetCombo, res.fileset_list); - fill(levelCombo, res.levels); - fill(clientCombo, res.client_list); - fill(poolCombo, res.pool_list); - fill(storageCombo, res.storage_list); - dateTimeEdit->setDisplayFormat("yyyy-MM-dd hh:mm:ss"); - dateTimeEdit->setDateTime(dt.currentDateTime()); - fill(messagesCombo, res.messages_list); - messagesCombo->setEnabled(false); - job_name_change(0); - connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int))); - connect(cancelButton, SIGNAL(pressed()), this, SLOT(deleteLater())); - connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed())); - show(); - } - -private slots: - - void okButtonPushed() - { - QString cmd; - cmd = "run"; - if (jobCombo->isEnabled()) { - cmd += " job=\"" + jobCombo->currentText() + "\"" ; - } - if (filesetCombo->isEnabled()) { - cmd += " fileset=\"" + filesetCombo->currentText() + "\""; - } - cmd += " level=\"" + levelCombo->currentText() + "\""; - if (clientCombo->isEnabled()) { - cmd += " client=\"" + clientCombo->currentText() + "\"" ; - } - if (poolCombo->isEnabled()) { - cmd += " pool=\"" + poolCombo->currentText() + "\""; - } - if (storageCombo->isEnabled()) { - cmd += " storage=\"" + storageCombo->currentText() + "\""; - } - cmd += " priority=\"" + QString().setNum(prioritySpin->value()) + "\""; - cmd += " when=\"" + dateTimeEdit->dateTime().toString("yyyy-MM-dd hh:mm:ss") + "\""; -#ifdef xxx - " messages=\"" << messagesCombo->currentText() << "\""; - /* FIXME when there is an option to modify the messages resoruce associated - * with a job */ -#endif - cmd += " yes"; - qDebug() << cmd; - item->D_sock->fsend("%s", cmd.toUtf8().data()); - QString output; - while(bnet_recv(item->D_sock) >= 0) {output += item->D_sock->msg;} - QMessageBox msgBox; - msgBox.setText(output); - msgBox.exec(); - deleteLater(); - } - - void job_name_change(int) - { - job_defaults job_defs; - job_defs.job_name = jobCombo->currentText(); - - if (item->get_job_defaults(job_defs)) { - typeLabel->setText("

"+job_defs.type+"

"); - filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly)); - levelCombo->setCurrentIndex(levelCombo->findText(job_defs.level, Qt::MatchExactly)); - clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly)); - poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly)); - storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly)); - messagesCombo->setCurrentIndex(messagesCombo->findText(job_defs.messages_name, Qt::MatchExactly)); - - } else { - - } - } -}; - -void refresh_item(); -void dotest(); - -class TrayUI: public QMainWindow -{ - Q_OBJECT - -public: - QWidget *centralwidget; - QTabWidget *tabWidget; - QStatusBar *statusbar; - QHash hash; - monitoritem* director; - - QSystemTrayIcon *tray; - QSpinBox *spinRefresh; - QTimer *timer; - - QPlainTextEdit *getTextEdit(char *title) - { - return hash.value(QString(title)); - } - - void clearText(char *title) - { - QPlainTextEdit *w = getTextEdit(title); - if (!w) { - return; - } - w->clear(); - } - - void appendText(char *title, char *line) - { - QPlainTextEdit *w = getTextEdit(title); - if (!w) { - return; - } - w->appendPlainText(QString(line)); - } - - void addDirector(monitoritem *item) - { - director = item; - } - - void addTab(char *title) - { - QString t = QString(title); - QWidget *tab = new QWidget(); - QVBoxLayout *vLayout = new QVBoxLayout(tab); - QPlainTextEdit *plainTextEdit = new QPlainTextEdit(tab); - plainTextEdit->setObjectName(t); - plainTextEdit->setReadOnly(true); - plainTextEdit->setFont(QFont("courier")); - vLayout->addWidget(plainTextEdit); - hash.insert(t, plainTextEdit); - tabWidget->addTab(tab, t); - } - - void startTimer() - { - if (!timer) { - timer = new QTimer(this); - connect(timer, SIGNAL(timeout()), this, SLOT(refresh_screen())); - } - timer->start(spinRefresh->value()*1000); - } - - void setupUi(QMainWindow *TrayMonitor) - { - timer = NULL; - director = NULL; - if (TrayMonitor->objectName().isEmpty()) - TrayMonitor->setObjectName(QString::fromUtf8("TrayMonitor")); - TrayMonitor->setWindowIcon(QIcon(":/images/cartridge.png")); - TrayMonitor->resize(789, 595); - centralwidget = new QWidget(TrayMonitor); - centralwidget->setObjectName(QString::fromUtf8("centralwidget")); - QVBoxLayout *verticalLayout = new QVBoxLayout(centralwidget); - verticalLayout->setObjectName(QString::fromUtf8("verticalLayout")); - tabWidget = new QTabWidget(centralwidget); - tabWidget->setObjectName(QString::fromUtf8("tabWidget")); - tabWidget->setTabPosition(QTabWidget::North); - tabWidget->setTabShape(QTabWidget::Rounded); - tabWidget->setTabsClosable(false); - verticalLayout->addWidget(tabWidget); - - QDialogButtonBox *buttonBox = new QDialogButtonBox(centralwidget); - buttonBox->setObjectName(QString::fromUtf8("buttonBox")); - buttonBox->setStandardButtons(QDialogButtonBox::Close); - connect(buttonBox, SIGNAL(rejected()), this, SLOT(cb_show())); - - TrayMonitor->setCentralWidget(centralwidget); - statusbar = new QStatusBar(TrayMonitor); - statusbar->setObjectName(QString::fromUtf8("statusbar")); - TrayMonitor->setStatusBar(statusbar); - - QHBoxLayout *hLayout = new QHBoxLayout(); - QLabel *refreshlabel = new QLabel(centralwidget); - refreshlabel->setText("Refresh:"); - hLayout->addWidget(refreshlabel); - spinRefresh = new QSpinBox(centralwidget); - QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - sizePolicy.setHorizontalStretch(0); - sizePolicy.setVerticalStretch(0); - sizePolicy.setHeightForWidth(spinRefresh->sizePolicy().hasHeightForWidth()); - spinRefresh->setSizePolicy(sizePolicy); - spinRefresh->setMinimum(1); - spinRefresh->setMaximum(600); - spinRefresh->setSingleStep(10); - spinRefresh->setValue(60); - hLayout->addWidget(spinRefresh); - hLayout->addWidget(buttonBox); - - verticalLayout->addLayout(hLayout); - - tray = new QSystemTrayIcon(TrayMonitor); - QMenu* stmenu = new QMenu(TrayMonitor); - - QAction *actShow = new QAction(QApplication::translate("TrayMonitor", - "Display", - 0, QApplication::UnicodeUTF8),TrayMonitor); - QAction* actQuit = new QAction(QApplication::translate("TrayMonitor", - "Quit", - 0, QApplication::UnicodeUTF8),TrayMonitor); - QAction* actAbout = new QAction(QApplication::translate("TrayMonitor", - "About", - 0, QApplication::UnicodeUTF8),TrayMonitor); - QAction* actRun = new QAction(QApplication::translate("TrayMonitor", - "Run...", - 0, QApplication::UnicodeUTF8),TrayMonitor); - stmenu->addAction(actShow); - stmenu->addAction(actRun); - stmenu->addAction(actAbout); - stmenu->addSeparator(); - stmenu->addAction(actQuit); - - connect(actRun, SIGNAL(triggered()), this, SLOT(cb_run())); - connect(actShow, SIGNAL(triggered()), this, SLOT(cb_show())); - connect(actQuit, SIGNAL(triggered()), this, SLOT(cb_quit())); - connect(actAbout, SIGNAL(triggered()), this, SLOT(cb_about())); - connect(spinRefresh, SIGNAL(valueChanged(int)), this, SLOT(cb_refresh(int))); - connect(tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), - this, SLOT(cb_trayIconActivated(QSystemTrayIcon::ActivationReason))); - - tray->setContextMenu(stmenu); - QIcon icon(":/images/cartridge.png"); - tray->setIcon(icon); - tray->setToolTip(QString("Bareos Tray Monitor")); - tray->show(); - - retranslateUi(TrayMonitor); - QMetaObject::connectSlotsByName(TrayMonitor); - } // setupUi - - void retranslateUi(QMainWindow *TrayMonitor) - { - TrayMonitor->setWindowTitle(QApplication::translate("TrayMonitor", "Bareos Tray Monitor", 0, QApplication::UnicodeUTF8)); - } // retranslateUi - -private slots: - void cb_quit() { - QApplication::quit(); - } - - void cb_refresh(int val) { - if (timer) { - timer->setInterval(val*1000); - } - } - - void cb_about() { - QMessageBox::about(this, tr("About Bareos Tray Monitor"), - tr("

Bareos Tray Monitor %1

" - "

For more information, see: www.bareos.com" - "

Copyright © 1999-2010, Bacula Systems(R) SA" - "

BAREOS® is a registered trademark of Bareos GmbH & Co. KG" - "

Licensed under GNU AGPLv3.").arg(VERSION).arg(BYEAR)); - } - - void cb_run() { - if (director) { - RunDlg *runbox = new RunDlg(director); - runbox->show(); - } - } - - void cb_trayIconActivated(QSystemTrayIcon::ActivationReason r) { - if (r == QSystemTrayIcon::Trigger) { - cb_show(); - } - } - - void refresh_screen() { -// qDebug() << "refresh_screen()"; - if (isVisible()) { - refresh_item(); -// qDebug() << " -> OK"; - } - } - - void cb_show() { - if (isVisible()) { - hide(); - } else { - refresh_item(); - show(); - } - } -}; - - -#endif /* TRAYUI_H */ diff --git a/src/qt-console/tray-monitor/authenticate.cpp b/src/qt-tray-monitor/authenticate.cpp similarity index 83% rename from src/qt-console/tray-monitor/authenticate.cpp rename to src/qt-tray-monitor/authenticate.cpp index 9394bc24369..7618f24c19c 100644 --- a/src/qt-console/tray-monitor/authenticate.cpp +++ b/src/qt-tray-monitor/authenticate.cpp @@ -2,6 +2,8 @@ BAREOS® - Backup Archiving REcovery Open Sourced Copyright (C) 2004-2008 Free Software Foundation Europe e.V. + Copyright (C) 2011-2012 Planets Communications B.V. + Copyright (C) 2013-2013 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -24,8 +26,10 @@ * Nicolas Boichat, August MMIV */ -#include "tray-monitor.h" +#include "monitoritem.h" +#include "authenticate.h" #include "jcr.h" +#include "monitoritemthread.h" void senditf(const char *fmt, ...); void sendit(const char *buf); @@ -50,8 +54,10 @@ static char FDOKhello[] = "2000 OK Hello"; /* * Authenticate Director */ -int authenticate_director(JCR *jcr, MONITORRES *mon, DIRRES *director) +static int authenticate_director(JCR *jcr) { + const MONITORRES *monitor = MonitorItemThread::instance()->getMonitor(); + BSOCK *dir = jcr->dir_bsock; int tls_local_need = BNET_TLS_NONE; int tls_remote_need = BNET_TLS_NONE; @@ -59,9 +65,9 @@ int authenticate_director(JCR *jcr, MONITORRES *mon, DIRRES *director) char bashed_name[MAX_NAME_LENGTH]; char *password; - bstrncpy(bashed_name, mon->hdr.name, sizeof(bashed_name)); + bstrncpy(bashed_name, monitor->hdr.name, sizeof(bashed_name)); bash_spaces(bashed_name); - password = mon->password; + password = monitor->password; /* Timeout Hello after 5 mins */ btimer_t *tid = start_bsock_timer(dir, 60 * 5); @@ -97,8 +103,10 @@ int authenticate_director(JCR *jcr, MONITORRES *mon, DIRRES *director) /* * Authenticate Storage daemon connection */ -int authenticate_storage_daemon(JCR *jcr, MONITORRES *monitor, STORERES* store) +static int authenticate_storage_daemon(JCR *jcr, STORERES* store) { + const MONITORRES *monitor = MonitorItemThread::instance()->getMonitor(); + BSOCK *sd = jcr->store_bsock; char dirname[MAX_NAME_LENGTH]; int tls_local_need = BNET_TLS_NONE; @@ -143,8 +151,10 @@ int authenticate_storage_daemon(JCR *jcr, MONITORRES *monitor, STORERES* store) /* * Authenticate File daemon connection */ -int authenticate_file_daemon(JCR *jcr, MONITORRES *monitor, CLIENTRES* client) +static int authenticate_file_daemon(JCR *jcr, CLIENTRES* client) { + const MONITORRES *monitor = MonitorItemThread::instance()->getMonitor(); + BSOCK *fd = jcr->file_bsock; char dirname[MAX_NAME_LENGTH]; int tls_local_need = BNET_TLS_NONE; @@ -185,3 +195,19 @@ int authenticate_file_daemon(JCR *jcr, MONITORRES *monitor, CLIENTRES* client) } return 1; } + +int authenticate_daemon(MonitorItem* item, JCR *jcr) +{ + switch (item->type()) { + case R_DIRECTOR: + return authenticate_director(jcr); + case R_CLIENT: + return authenticate_file_daemon(jcr, (CLIENTRES*)item->resource()); + case R_STORAGE: + return authenticate_storage_daemon(jcr, (STORERES*)item->resource()); + default: + printf(_("Error, currentitem is not a Client or a Storage..\n")); + return FALSE; + } + return false; +} diff --git a/src/qt-tray-monitor/authenticate.h b/src/qt-tray-monitor/authenticate.h new file mode 100644 index 00000000000..7b6a613d7e1 --- /dev/null +++ b/src/qt-tray-monitor/authenticate.h @@ -0,0 +1,10 @@ +#ifndef AUTHENTICATE_H_INCLUDED +#define AUTHENTICATE_H_INCLUDED + +class MONITORRES; +class MonitorItem; +class JCR; + +int authenticate_daemon(MonitorItem* item, JCR *jcr); + +#endif // AUTHENTICATE_H_INCLUDED diff --git a/src/qt-tray-monitor/bareos-tray-monitor.desktop b/src/qt-tray-monitor/bareos-tray-monitor.desktop new file mode 100644 index 00000000000..f20d4581c67 --- /dev/null +++ b/src/qt-tray-monitor/bareos-tray-monitor.desktop @@ -0,0 +1,13 @@ +[Desktop Entry] +X-SuSE-translate=true +Name=Bareos Tray Monitor +GenericName=Backup Tray Monitor +Comment=Notification Tray Monitor +Icon=bareos-tray-monitor +Exec=/home/pstorz/bareos/sbin/bareos-tray-monitor -c /home/pstorz/bareos/etc/tray-monitor.conf +Terminal=false +Type=Application +Encoding=UTF-8 +X-Desktop-File-Install-Version=0.3 +Categories=System;Utility;Archiving;X-SuSE-Backup; +#TrayIcon; diff --git a/src/qt-console/tray-monitor/bareos-tray-monitor.desktop.in b/src/qt-tray-monitor/bareos-tray-monitor.desktop.in similarity index 100% rename from src/qt-console/tray-monitor/bareos-tray-monitor.desktop.in rename to src/qt-tray-monitor/bareos-tray-monitor.desktop.in diff --git a/src/qt-console/tray-monitor/bareos-tray-monitor.xpm b/src/qt-tray-monitor/bareos-tray-monitor.xpm similarity index 100% rename from src/qt-console/tray-monitor/bareos-tray-monitor.xpm rename to src/qt-tray-monitor/bareos-tray-monitor.xpm diff --git a/src/qt-tray-monitor/main.qrc b/src/qt-tray-monitor/main.qrc new file mode 100644 index 00000000000..0bb52b41e96 --- /dev/null +++ b/src/qt-tray-monitor/main.qrc @@ -0,0 +1,8 @@ + + + ../images/f.png + ../images/W.png + ../images/bareos_1.png + ../images/bareos_2.png + + diff --git a/src/qt-tray-monitor/mainwindow.cpp b/src/qt-tray-monitor/mainwindow.cpp new file mode 100644 index 00000000000..02b0aa86365 --- /dev/null +++ b/src/qt-tray-monitor/mainwindow.cpp @@ -0,0 +1,200 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2013-2013 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "systemtrayicon.h" + +#include + +#include +#include +#include +#include + +#include "tray-monitor.h" +#include "monitoritemthread.h" +#include "monitoritem.h" +#include "monitortab.h" + +MainWindow* MainWindow::mainWindowSingleton = NULL; +bool MainWindow::already_destroyed = false; + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) + , monitorTabMap(new QMap) + , systemTrayIcon(new SystemTrayIcon(this)) +{ + /* Init the SystemTrayIcon first to have all its signals + * configured to be auto-connected via connectSlotsByName(MainWindow) + * during ui->setupUi(this). */ + Q_ASSERT(systemTrayIcon->objectName() == "SystemTrayIcon"); + + // This will setup the tab-window and auto-connect signals and slots. + ui->setupUi(this); + setWindowTitle(tr("Bareos Tray Monitor")); + setWindowIcon(QIcon(":images/bareos_1.png")); + ui->pushButton_Close->setIcon(QIcon(":images/f.png")); + + // Prepare the tabWidget + while (ui->tabWidget->count()) { + ui->tabWidget->removeTab(0); + } + + // Now show the tray icon, but leave the MainWindow hidden. + systemTrayIcon->show(); +} + +MainWindow::~MainWindow() +{ + delete ui; + delete monitorTabMap; +} + +MainWindow* MainWindow::instance() +{ + // improve that the MainWindow is created + // and deleted only once during program execution + Q_ASSERT(!already_destroyed); + + if (!mainWindowSingleton) { + mainWindowSingleton = new MainWindow; + } + + return mainWindowSingleton; +} + +void MainWindow::destruct() +{ + if (mainWindowSingleton) { + delete mainWindowSingleton; + mainWindowSingleton = NULL; + } +} + +void MainWindow::addTabs(QStringList tabRefs) +{ + for (int i = 0; i < tabRefs.count(); i++) { + MonitorTab* tab = new MonitorTab(tabRefs[i], this); + monitorTabMap->insert(tabRefs[i], tab); //tabRefs[i] used as reference + ui->tabWidget->addTab(tab->getTabWidget(), tabRefs[i]); + } +} + +void MainWindow::on_TrayMenu_About_triggered() +{ + QString fmt = QString("

Bareos Tray Monitor %1

" + "

For more information, see: www.bareos.com" + "

Copyright © 2004-2011 Free Software Foundation Europe e.V." + "

Copyright © 2011-2012 Planets Communications B.V." + "

Copyright © 2013-%2 Bareos GmbH & Co. KG" + "

BAREOS ® is a registered trademark of Bareos GmbH & Co. KG" + "

Licensed under GNU AGPLv3.").arg(VERSION).arg(BYEAR); + + QMessageBox::about(this, tr("About Bareos Tray Monitor"), fmt); +} + +void MainWindow::on_TrayMenu_Quit_triggered() +{ + QApplication::quit(); +} + +void MainWindow::on_TrayMenu_Display_triggered() +{ + if (isVisible()) { + hide(); + } else { + show(); + raise(); + emit refreshItems(); + } +} + +void MainWindow::on_SystemTrayIcon_activated(QSystemTrayIcon::ActivationReason r) +{ + if (r == QSystemTrayIcon::Trigger) { + on_TrayMenu_Display_triggered(); + } +} + +void MainWindow::on_pushButton_Close_clicked() +{ + hide(); +} + +QPlainTextEdit* MainWindow::getTextEdit(const QString& tabRef) +{ + MonitorTab* tab = monitorTabMap->value(tabRef); + + return (tab) ? tab->getTextEdit() : 0; +} + +void MainWindow::onClearText(const QString& tabRef) +{ + QPlainTextEdit *w = getTextEdit(tabRef); + + if (w) { + w->clear(); + } +} + +void MainWindow::onAppendText(QString tabRef, QString line) +{ + QPlainTextEdit *w = getTextEdit(tabRef); + + if (w) { + w->appendPlainText(line); + } +} + +void MainWindow::onShowStatusbarMessage(QString message) +{ + ui->statusbar->showMessage(message, 3000); +} + +void MainWindow::onStatusChanged(const QString &tabRef, int state) +{ + MonitorTab* tab = monitorTabMap->value(tabRef); + + if (tab) { + int idx = ui->tabWidget->indexOf(tab->getTabWidget()); + if (idx < 0) { + return; + } + + switch(state) { + case MonitorItem::Error: + ui->tabWidget->setTabIcon(idx, QIcon(":images/W.png")); + break; + case MonitorItem::Running: + ui->tabWidget->setTabIcon(idx, QIcon()); + break; + default: + break; + } /* switch(state) */ + } /* if (tab) */ +} + +void MainWindow::onFdJobIsRunning(bool running) +{ + systemTrayIcon->animateIcon(running); +} diff --git a/src/qt-tray-monitor/mainwindow.h b/src/qt-tray-monitor/mainwindow.h new file mode 100644 index 00000000000..09705e77b4e --- /dev/null +++ b/src/qt-tray-monitor/mainwindow.h @@ -0,0 +1,92 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2013-2013 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace Ui { +class MainWindow; +} + +class QPlainTextEdit; +class MonitorTab; +class MonitorItem; +class SystemTrayIcon; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + static MainWindow* instance(); + static void destruct(); + + void addTabs(QStringList tabRefs); + +private: + explicit MainWindow(QWidget *parent = 0); + Q_DISABLE_COPY(MainWindow); + ~MainWindow(); + + QPlainTextEdit* getTextEdit(const QString& tabRef); + static MainWindow* mainWindowSingleton; + static bool already_destroyed; + + Ui::MainWindow *ui; + QMap* monitorTabMap; + SystemTrayIcon* systemTrayIcon; + +public slots: + /* auto-connected slots to the UI */ + void on_pushButton_Close_clicked(); + /* ********************************************* */ + + /* auto-connected slots to the TrayMenu Actions */ + void on_TrayMenu_About_triggered(); + void on_TrayMenu_Quit_triggered(); + void on_TrayMenu_Display_triggered(); + /* ********************************************* */ + + /* auto-connected slots to the SystemTrayIcon */ + void on_SystemTrayIcon_activated(QSystemTrayIcon::ActivationReason); + /* ********************************************* */ + + void onShowStatusbarMessage(QString); + void onAppendText(QString, QString); + void onClearText(const QString& tabRef); + void onStatusChanged(const QString& tabRef, int state); + void onFdJobIsRunning(bool running); + +signals: + void refreshItems(); +}; + +#endif // MAINWINDOW_H diff --git a/src/qt-tray-monitor/mainwindow.ui b/src/qt-tray-monitor/mainwindow.ui new file mode 100644 index 00000000000..7076be9ad11 --- /dev/null +++ b/src/qt-tray-monitor/mainwindow.ui @@ -0,0 +1,62 @@ + + + MainWindow + + + + 0 + 0 + 800 + 542 + + + + MainWindow + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Close + + + + + + + + + + Tab 1 + + + + + Tab 2 + + + + + + + + + + + diff --git a/src/qt-tray-monitor/monitoritem.cpp b/src/qt-tray-monitor/monitoritem.cpp new file mode 100644 index 00000000000..efd1a104b2b --- /dev/null +++ b/src/qt-tray-monitor/monitoritem.cpp @@ -0,0 +1,353 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2013-2013 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ +#include +#include + +#include "monitoritem.h" +#include "authenticate.h" +#include "monitoritemthread.h" + +MonitorItem::MonitorItem(QObject* parent) + : QObject(parent) + , d(new MonitorItemPrivate) +{ + /* Run this class only in the context of + MonitorItemThread because of the networking */ + Q_ASSERT(QThread::currentThreadId() == MonitorItemThread::instance()->getThreadId()); +} + +MonitorItem::~MonitorItem() +{ + delete d; +} + +char* MonitorItem::get_name() const +{ + return static_cast(d->resource)->hdr.name; +} + +void MonitorItem::writecmd(const char* command) +{ + if (d->DSock) { + d->DSock->msglen = pm_strcpy(&d->DSock->msg, command); + bnet_send(d->DSock); + } +} + +bool MonitorItem::get_job_defaults(struct JobDefaults &job_defs) +{ + int stat; + char *def; + BSOCK *dircomm; + bool rtn = false; + QString scmd = QString(".defaults job=\"%1\"").arg(job_defs.job_name); + + if (job_defs.job_name == "") { + return rtn; + } + + if (!doconnect()) { + return rtn; + } + dircomm = d->DSock; + dircomm->fsend("%s", scmd.toUtf8().data()); + + while ((stat = dircomm->recv()) > 0) { + def = strchr(dircomm->msg, '='); + if (!def) { + continue; + } + /* Pointer to default value */ + *def++ = 0; + strip_trailing_newline(def); + + if (strcmp(dircomm->msg, "job") == 0) { + if (strcmp(def, job_defs.job_name.toUtf8().data()) != 0) { + goto bail_out; + } + continue; + } + if (strcmp(dircomm->msg, "pool") == 0) { + job_defs.pool_name = def; + continue; + } + if (strcmp(dircomm->msg, "messages") == 0) { + job_defs.messages_name = def; + continue; + } + if (strcmp(dircomm->msg, "client") == 0) { + job_defs.client_name = def; + continue; + } + if (strcmp(dircomm->msg, "storage") == 0) { + job_defs.store_name = def; + continue; + } + if (strcmp(dircomm->msg, "where") == 0) { + job_defs.where = def; + continue; + } + if (strcmp(dircomm->msg, "level") == 0) { + job_defs.level = def; + continue; + } + if (strcmp(dircomm->msg, "type") == 0) { + job_defs.type = def; + continue; + } + if (strcmp(dircomm->msg, "fileset") == 0) { + job_defs.fileset_name = def; + continue; + } + if (strcmp(dircomm->msg, "catalog") == 0) { + job_defs.catalog_name = def; + continue; + } + if (strcmp(dircomm->msg, "enabled") == 0) { + job_defs.enabled = *def == '1' ? true : false; + continue; + } + } + rtn = true; + /* Fall through wanted */ +bail_out: + return rtn; +} + +bool MonitorItem::doconnect() +{ + if (d->DSock) { + //already connected + return true; + } + + JCR jcr; + memset(&jcr, 0, sizeof(jcr)); + + DIRRES* dird; + CLIENTRES* filed; + STORERES* stored; + QString message; + + switch (d->type) { + case R_DIRECTOR: + dird = static_cast(d->resource); + message = QString("Connecting to Director %1:%2").arg(dird->address).arg(dird->DIRport); + emit showStatusbarMessage(message); + d->DSock = bnet_connect(NULL, d->connectTimeout, + 0, 0, "Director daemon", dird->address, NULL, dird->DIRport, 0); + jcr.dir_bsock = d->DSock; + break; + case R_CLIENT: + filed = static_cast(d->resource); + message = QString("Connecting to Client %1:%2").arg(filed->address).arg(filed->FDport); + emit showStatusbarMessage(message); + d->DSock = bnet_connect(NULL, d->connectTimeout, + 0, 0, "File daemon", filed->address, NULL, filed->FDport, 0); + jcr.file_bsock = d->DSock; + break; + case R_STORAGE: + stored = static_cast(d->resource); + message = QString("Connecting to Storage %1:%2").arg(stored->address).arg(stored->SDport); + emit showStatusbarMessage(message); + d->DSock = bnet_connect(NULL, d->connectTimeout, + 0, 0, "Storage daemon", stored->address, NULL, stored->SDport, 0); + jcr.store_bsock = d->DSock; + break; + default: + printf("Error, currentitem is not a Client, a Storage or a Director..\n"); + return false; + } + + if (d->DSock == NULL) { + emit showStatusbarMessage("Cannot connect to daemon."); + emit clearText(get_name()); + emit appendText(get_name(), QString("Cannot connect to daemon.")); + d->state = MonitorItem::Error; + emit statusChanged(get_name(), d->state); + return false; + } + + if (!authenticate_daemon(this, &jcr)) { + d->state = MonitorItem::Error; + emit statusChanged(get_name(), d->state); + message = QString("Authentication error : %1").arg(d->DSock->msg); + emit showStatusbarMessage(message); + emit clearText(get_name()); + emit appendText(get_name(), QString("Authentication error : %1").arg(d->DSock->msg)); + d->DSock = NULL; + return false; + } + + switch (d->type) { + case R_DIRECTOR: + emit showStatusbarMessage("Opened connection with Director daemon."); + break; + case R_CLIENT: + emit showStatusbarMessage("Opened connection with File daemon."); + break; + case R_STORAGE: + emit showStatusbarMessage("Opened connection with Storage daemon."); + break; + default: + emit showStatusbarMessage("Error, currentitem is not a Client, a Storage or a Director..\n"); + d->state = Error; + emit statusChanged(get_name(), d->state); + return false; + } + + if (d->type == R_DIRECTOR) { /* Read connection messages... */ + docmd(""); /* Usually invalid, but no matter */ + } + + d->state = Running; + emit statusChanged(get_name(), d->state); + + return true; +} + +void MonitorItem::disconnect() +{ + if (d->DSock) { + writecmd("quit"); + d->DSock->signal(BNET_TERMINATE); /* send EOF */ + d->DSock->close(); + d->DSock = NULL; + } +} + +bool MonitorItem::docmd(const char* command) +{ + if (!doconnect()) { + return false; + } + + if (command[0] != 0) { + writecmd(command); + } + + emit clearText(get_name()); + bool jobRunning = false; + + while (1) { + int stat; + if ((stat = bnet_recv(d->DSock)) >= 0) { + strip_trailing_newline(d->DSock->msg); + QString msg = QString::fromUtf8(d->DSock->msg); + emit appendText(QString::fromUtf8(get_name()), msg); + if (d->type == R_CLIENT) { + if (msg.contains("Job started:")) + jobRunning = true; + } + } else if (stat == BNET_SIGNAL) { + if (d->DSock->msglen == BNET_EOD) { + // qDebug() << "<< EOD >>"; + if (d->type == R_CLIENT) + emit jobIsRunning (jobRunning); + return true; + } + else if (d->DSock->msglen == BNET_SUB_PROMPT) { + // qDebug() << "<< PROMPT >>"; + return false; + } + else if (d->DSock->msglen == BNET_HEARTBEAT) { + bnet_sig(d->DSock, BNET_HB_RESPONSE); + } + else { + qDebug() << bnet_sig_to_ascii(d->DSock); + } + } else { /* BNET_HARDEOF || BNET_ERROR */ + d->DSock = NULL; + d->state = MonitorItem::Error; + emit statusChanged(get_name(), d->state); + emit showStatusbarMessage("Error : BNET_HARDEOF or BNET_ERROR"); + //fprintf(stderr, "<< ERROR >>\n")); + return false; + } /* if ((stat = bnet_recv(d->DSock)) >= 0) */ + + if (is_bnet_stop(d->DSock)) { + d->DSock = NULL; + d->state = MonitorItem::Error; + emit statusChanged(get_name(), d->state); + emit showStatusbarMessage("Error : Connection closed."); + //fprintf(stderr, "<< STOP >>\n"); + return false; /* error or term */ + } /* if (is_bnet_stop(d->DSock) */ + + } /* while (1) */ +} + +void MonitorItem::get_list(const char *cmd, QStringList &lst) +{ + doconnect(); + writecmd(cmd); + while (bnet_recv(d->DSock) >= 0) { + strip_trailing_newline(d->DSock->msg); + if (*(d->DSock->msg)) { + lst << QString(d->DSock->msg); + } + } +} + +void MonitorItem::get_status() +{ + switch (d->type) { + case R_DIRECTOR: + docmd("status dir"); + break; + case R_CLIENT: + docmd("status"); + break; + case R_STORAGE: + docmd("status"); + break; + default: + break; + } +} + +void MonitorItem::connectToMainWindow(QObject* mainWindow) +{ + connect(this, SIGNAL(showStatusbarMessage(QString)), + mainWindow, SLOT(onShowStatusbarMessage(QString))); + connect(this, SIGNAL(appendText(QString,QString)), + mainWindow, SLOT(onAppendText(QString,QString))); + connect(this, SIGNAL(clearText(QString)), + mainWindow, SLOT(onClearText(QString))); + connect(this, SIGNAL(statusChanged(QString,int)), + mainWindow, SLOT(onStatusChanged(QString,int))); + if (d->type == R_CLIENT) { + connect(this, SIGNAL(jobIsRunning(bool)), + mainWindow, SLOT(onFdJobIsRunning(bool))); + } +} + +Rescode MonitorItem::type() const { return d->type; } +void* MonitorItem::resource() const { return d->resource; } +BSOCK* MonitorItem::DSock() const { return d->DSock; } +MonitorItem::StateEnum MonitorItem::state() const { return d->state; } +int MonitorItem::connectTimeout() const { return d->connectTimeout; } + +void MonitorItem::setType(Rescode type) { d->type = type; } +void MonitorItem::setResource(void* resource) { d->resource = resource; } +void MonitorItem::setDSock(BSOCK* DSock) { d->DSock = DSock; } +void MonitorItem::setState(MonitorItem::StateEnum state) { d->state = state; } +void MonitorItem::setConnectTimeout(int timeout) { d->connectTimeout = timeout; } diff --git a/src/qt-tray-monitor/monitoritem.h b/src/qt-tray-monitor/monitoritem.h new file mode 100644 index 00000000000..f5e85cb6029 --- /dev/null +++ b/src/qt-tray-monitor/monitoritem.h @@ -0,0 +1,136 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2013-2013 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#ifndef MONITORITEM_H_INCLUDED +#define MONITORITEM_H_INCLUDED + +#include +#include +#include + +#include "bareos.h" +#include "tray_conf.h" +#include "jcr.h" +#include "tray-monitor.h" + +class MonitorItemPrivate; + +class MonitorItem : public QObject +{ + Q_OBJECT + +public: + + enum StateEnum + { + Idle = 0, + Running = 1, + Warn = 2, + Error = 3 + }; + + class JobDefaults + { + public: + QString job_name; + QString pool_name; + QString messages_name; + QString client_name; + QString store_name; + QString where; + QString level; + QString type; + QString fileset_name; + QString catalog_name; + bool enabled; + }; + + class Resources { + public: + QStringList job_list; + QStringList pool_list; + QStringList client_list; + QStringList storage_list; + QStringList levels; + QStringList fileset_list; + QStringList messages_list; + }; + +public: + MonitorItem(QObject* parent = 0); + ~MonitorItem(); + + char *get_name() const; + void writecmd(const char* command); + bool get_job_defaults(struct JobDefaults &job_defs); + bool doconnect(); + void disconnect(); + bool docmd(const char* command); + void connectToMainWindow(QObject* mainWindow); + void get_list(const char *cmd, QStringList &lst); + void get_status(); + + Rescode type() const; + void* resource() const; + BSOCK* DSock() const; + StateEnum state() const; + int connectTimeout() const; + + void setType(Rescode type); + void setResource(void* resource); + void setDSock(BSOCK* DSock); + void setState(StateEnum state); + void setConnectTimeout(int timeout); + +private: + Q_DISABLE_COPY(MonitorItem); + MonitorItemPrivate* d; + +public slots: +signals: + void showStatusbarMessage(const QString& message); + void appendText(const QString& tabRef, const QString& message); + void clearText(const QString& tabRef); + void statusChanged(const QString&tabRef, int); + void jobIsRunning(bool); +}; + +class MonitorItemPrivate +{ + friend class MonitorItem; + + MonitorItemPrivate() + : type(R_UNKNOWN) + , resource(NULL) + , DSock(NULL) + , connectTimeout(0) + , state(MonitorItem::Idle) + { } + + Rescode type; /* R_DIRECTOR, R_CLIENT or R_STORAGE */ + void* resource; /* DIRRES*, CLIENTRES* or STORERES* */ + BSOCK* DSock; + int connectTimeout; + + MonitorItem::StateEnum state; +}; + +#endif // MONITORITEM_H_INCLUDED diff --git a/src/qt-tray-monitor/monitoritemthread.cpp b/src/qt-tray-monitor/monitoritemthread.cpp new file mode 100644 index 00000000000..1a7ac6f4fe1 --- /dev/null +++ b/src/qt-tray-monitor/monitoritemthread.cpp @@ -0,0 +1,228 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2013-2013 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ +#include +#include + +#include "mainwindow.h" +#include "monitoritemthread.h" +#include "tray-monitor.h" +#include "monitoritem.h" +#include "tray_conf.h" + +MonitorItemThread* MonitorItemThread::monitorItemThreadSingleton; +bool MonitorItemThread::already_destroyed = false; + +MonitorItemThread::MonitorItemThread(QObject* parent) + : QThread(parent) + , monitor(NULL) + , refreshTimer(new QTimer(this)) + , isRefreshing(false) +{ + threadId = currentThreadId(); + + refreshTimer->setObjectName("RefreshTimer"); + QMetaObject::connectSlotsByName(this); +} + +MonitorItemThread::~MonitorItemThread() +{ + return; +} + +MonitorItemThread* MonitorItemThread::instance() +{ + // improve that the MonitorItemThread is created + // and deleted only once during program execution + Q_ASSERT(!already_destroyed); + + if (!monitorItemThreadSingleton) { + monitorItemThreadSingleton = new MonitorItemThread; + } + return monitorItemThreadSingleton; +} + +void MonitorItemThread::destruct() +{ + if (monitorItemThreadSingleton) { + monitorItemThreadSingleton->exit(0); + monitorItemThreadSingleton->wait(20000); + delete monitorItemThreadSingleton; + monitorItemThreadSingleton = NULL; + already_destroyed = true; + } +} + +Qt::HANDLE MonitorItemThread::getThreadId() +{ + return threadId; +} + +void MonitorItemThread::run() +{ + /* all this must be run in the same + * context of the MonitorItemThread */ + + lmgr_init_thread(); + + if (monitor) { + refreshTimer->start(monitor->RefreshInterval * 1000); + } + + exec(); + + while (items.count()) { + MonitorItem* item = items.first(); + item->disconnect(); + delete item; + items.removeFirst(); + } + + term_msg(); // this cannot be called twice, however +} + +QStringList MonitorItemThread::createRes(const cl_opts& cl) +{ + QStringList tabRefs; + + LockRes(); + + int monitorItems = 0; + MONITORRES *monitorRes; + foreach_res(monitorRes, R_MONITOR) { + monitorItems++; + } + + if (monitorItems != 1) { + Emsg2(M_ERROR_TERM, 0, + _("Error: %d Monitor resources defined in %s. " + "You must define one and only one Monitor resource.\n"), + monitorItems, cl.configfile); + } + + monitor = reinterpret_cast(GetNextRes(R_MONITOR, (RES *)NULL)); + + int nitems = 0; + + DIRRES* dird; + foreach_res(dird, R_DIRECTOR) { + MonitorItem* item = new MonitorItem; + item->setType(R_DIRECTOR); + item->setResource(dird); + item->setConnectTimeout(monitor->DIRConnectTimeout); + item->connectToMainWindow(MainWindow::instance()); + tabRefs.append(item->get_name()); + items.append(item); + nitems++; + } + + CLIENTRES* filed; + foreach_res(filed, R_CLIENT) { + MonitorItem* item = new MonitorItem; + item->setType(R_CLIENT); + item->setResource(filed); + item->setConnectTimeout(monitor->FDConnectTimeout); + item->connectToMainWindow(MainWindow::instance()); + tabRefs.append(item->get_name()); + items.append(item); + nitems++; + } + + STORERES* stored; + foreach_res(stored, R_STORAGE) { + MonitorItem* item = new MonitorItem; + item->setType(R_STORAGE); + item->setResource(stored); + item->setConnectTimeout(monitor->SDConnectTimeout); + item->connectToMainWindow(MainWindow::instance()); + tabRefs.append(item->get_name()); + items.append(item); + nitems++; + } + + UnlockRes(); + + if (nitems == 0) { + Emsg1(M_ERROR_TERM, 0, "No Client, Storage or Director resource defined in %s\n" + "Without that I don't know how to get status from the File, " + "Storage or Director Daemon :-(\n", cl.configfile); + } + + // check the refresh intervals for reasonable values + int interval = monitor->RefreshInterval; + if ((interval < 1) || (interval > 600)) { + Emsg2(M_ERROR_TERM, 0, "Invalid refresh interval defined in %s\n" + "This value must be greater or equal to 1 second and less or " + "equal to 10 minutes (read value: %d).\n", cl.configfile, interval); + } + + return tabRefs; +} + +void MonitorItemThread::onRefreshItems() +{ + if (!isRefreshing) { + isRefreshing = true; + for (int i = 0; i < items.count(); i++) { + items[i]->get_status(); + } + emit refreshItemsReady(); + isRefreshing = false; + } +} + +void MonitorItemThread::on_RefreshTimer_timeout() +{ + onRefreshItems(); +} + +MONITORRES* MonitorItemThread::getMonitor() const +{ + return monitor; +} + +MonitorItem* MonitorItemThread::getDirector() const +{ + // search for the first occurrence of a director + for (int i = 0; i < items.count(); i++) { + if (items[i]->type() == R_DIRECTOR) { + return items[i]; + } + } + return NULL; +} + + +/************* Testing ***************/ + +void MonitorItemThread::dotest() +{ + const char *cmd; + for (int i = 0; i < items.count(); i++) { + switch (items[i]->type()) { + case R_DIRECTOR: + cmd = ".jobs type=B"; + items[i]->docmd(cmd); + break; + default: + break; + } + } +} diff --git a/src/qt-tray-monitor/monitoritemthread.h b/src/qt-tray-monitor/monitoritemthread.h new file mode 100644 index 00000000000..85ef0224bfa --- /dev/null +++ b/src/qt-tray-monitor/monitoritemthread.h @@ -0,0 +1,75 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2013-2013 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ +#ifndef MONITORITEMTHREAD_H_INCLUDED +#define MONITORITEMTHREAD_H_INCLUDED + +#include "tray-monitor.h" + +#include +#include + +class MonitorItem; +class MONITORRES; +class QTimer; + +class MonitorItemThread : public QThread +{ + Q_OBJECT + +public: + static MonitorItemThread* instance(); + static void destruct(); + + Qt::HANDLE getThreadId(); + QStringList createRes(const cl_opts& cl); + MONITORRES* getMonitor() const; + MonitorItem *getDirector() const; + +protected: + virtual void run(); + void dotest(); + +private: + MonitorItemThread(QObject* parent = 0); + Q_DISABLE_COPY(MonitorItemThread); + virtual ~MonitorItemThread(); + + static MonitorItemThread* monitorItemThreadSingleton; + static bool already_destroyed; + MONITORRES* monitor; + Qt::HANDLE threadId; + + QList items; + QTimer* refreshTimer; + bool isRefreshing; + +public slots: + /* auto-connected slots to the Refresh Timer */ + void on_RefreshTimer_timeout(); + /* ********************************************* */ + + void onRefreshItems(); + +signals: + void refreshItemsReady(); +}; + +#endif // MONITORITEMTHREAD_H_INCLUDED diff --git a/src/qt-tray-monitor/monitortab.h b/src/qt-tray-monitor/monitortab.h new file mode 100644 index 00000000000..c28aa468f3d --- /dev/null +++ b/src/qt-tray-monitor/monitortab.h @@ -0,0 +1,33 @@ +#ifndef MONITORTAB_H +#define MONITORTAB_H + +class MonitorTab : public QObject +{ +public: + MonitorTab(QString tabRefString, QObject* parent = 0) + : QObject(parent) + , tab(new QWidget) + , textEdit(new QPlainTextEdit(tab)) + { + QVBoxLayout *vLayout = new QVBoxLayout(tab); + textEdit->setObjectName(tabRefString); + textEdit->setReadOnly(true); + textEdit->setFont(QFont("courier")); + vLayout->addWidget(textEdit); + } + + ~MonitorTab() + { + // do not delete widgets since they + // all have a parent that does the work + } + + QWidget* getTabWidget() const { return tab; } + QPlainTextEdit* getTextEdit() const { return textEdit; } + +private: + QWidget* tab; + QPlainTextEdit *textEdit; +}; + +#endif // MONITORTAB_H diff --git a/src/qt-tray-monitor/systemtrayicon.cpp b/src/qt-tray-monitor/systemtrayicon.cpp new file mode 100644 index 00000000000..7b86ed447b5 --- /dev/null +++ b/src/qt-tray-monitor/systemtrayicon.cpp @@ -0,0 +1,76 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2013-2013 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#include "systemtrayicon.h" +#include "traymenu.h" + +#include +#include +#include +#include + +SystemTrayIcon::SystemTrayIcon(QMainWindow* mainWindow) + : QSystemTrayIcon(mainWindow) + , iconIdx(0) + , timer(new QTimer(this)) +{ + // this object name is used for auto-connection to the MainWindow + setObjectName("SystemTrayIcon"); + + TrayMenu* menu = new TrayMenu(mainWindow); + setContextMenu(menu); + + icons << ":/images/bareos_1.png" << ":/images/bareos_2.png" ; + + setIcon(QIcon(icons[iconIdx])); + setToolTip("Bareos Tray Monitor"); + + timer->setInterval(700); + connect(timer, SIGNAL(timeout()), this, SLOT(setIconInternal())); +} + +SystemTrayIcon::~SystemTrayIcon() +{ + timer->stop(); +} + +void SystemTrayIcon::setIconInternal() +{ + setIcon(QIcon(icons[iconIdx])); + if (++iconIdx == icons.count()) { + iconIdx = 0; + } +} + +void SystemTrayIcon::animateIcon(bool on) +{ + if (on) { + if (!timer->isActive()) { + timer->start(); + } + } else { //off + if (timer->isActive()) { + timer->stop(); + } + iconIdx = 0; + setIconInternal(); + } +} diff --git a/src/qt-tray-monitor/systemtrayicon.h b/src/qt-tray-monitor/systemtrayicon.h new file mode 100644 index 00000000000..08ec2f443d3 --- /dev/null +++ b/src/qt-tray-monitor/systemtrayicon.h @@ -0,0 +1,54 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2013-2013 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#ifndef SYSTEMTRAYICON_H +#define SYSTEMTRAYICON_H + +#include + +class QMainWindow; +class QTimer; + +class SystemTrayIcon : public QSystemTrayIcon +{ + Q_OBJECT + +public: + SystemTrayIcon(QMainWindow* mainWindow); + virtual ~SystemTrayIcon(); + + void animateIcon(bool on); + +private: + Q_DISABLE_COPY(SystemTrayIcon); + SystemTrayIcon(); + QStringList icons; + + int iconIdx; + QTimer* timer; + +protected: + +public slots: + void setIconInternal(); +}; + +#endif // SYSTEMTRAYICON_H diff --git a/src/qt-console/tray-monitor/tray-monitor.conf.in b/src/qt-tray-monitor/tray-monitor.conf.in similarity index 100% rename from src/qt-console/tray-monitor/tray-monitor.conf.in rename to src/qt-tray-monitor/tray-monitor.conf.in diff --git a/src/qt-tray-monitor/tray-monitor.cpp b/src/qt-tray-monitor/tray-monitor.cpp new file mode 100644 index 00000000000..2fc92113153 --- /dev/null +++ b/src/qt-tray-monitor/tray-monitor.cpp @@ -0,0 +1,231 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2004-2011 Free Software Foundation Europe e.V. + Copyright (C) 2011-2012 Planets Communications B.V. + Copyright (C) 2013-2013 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#include +#include +#include +#include +#include + +#include "version.h" +#include "mainwindow.h" +#include "tray-monitor.h" +#include "authenticate.h" +#include "monitoritem.h" +#include "monitoritemthread.h" + +#define CONFIG_FILE "tray-monitor.conf" /* default configuration file */ + +/* Imported function from tray_conf.cpp */ +extern bool parse_tmon_config(CONFIG *config, const char *configfile, int exit_code); + +/* Static variables */ +static CONFIG* config = NULL; +static QApplication* app = NULL; + +static void usage() +{ + QString out; + out = out.sprintf( _( + PROG_COPYRIGHT + "\nVersion: %s (%s) %s %s %s\n\n" + "Usage: tray-monitor [-c config_file] [-d debug_level]\n" + " -c set configuration file to file\n" + " -d set debug level to \n" + " -dt print timestamp in debug output\n" + " -t test - read configuration and exit\n" + " -? print this message.\n" + "\n"), 2004, VERSION, BDATE, HOST_OS, DISTNAME, DISTVER); +#if HAVE_WIN32 + QMessageBox::information(0, "Help", out); +#else + fprintf(stderr, out.toUtf8()); +#endif + +} + +static void parse_command_line(int argc, char* argv[], cl_opts& cl) +{ + int ch; + while ((ch = getopt(argc, argv, "bc:d:th?f:s:")) != -1) { + switch (ch) { + case 'c': /* configuration file */ + if (cl.configfile) { + free(static_cast(cl.configfile)); + } + cl.configfile = bstrdup(optarg); + break; + + case 'd': + if (*optarg == 't') { + dbg_timestamp = true; + } else { + debug_level = atoi(optarg); + if (debug_level <= 0) { + debug_level = 1; + } + } + break; + + case 't': + cl.test_config_only = true; + break; + + case 'h': + case '?': + default: + usage(); + exit(1); + } + } + argc -= optind; + //argv += optind; + + if (argc) { + usage(); + exit(1); + } + + if (!cl.configfile) { + cl.configfile = bstrdup(CONFIG_FILE); + } +} + +static void setupQtObjects() +{ + MonitorItemThread* thr = MonitorItemThread::instance(); + MainWindow* win = MainWindow::instance(); + + QObject::connect(win, SIGNAL(refreshItems()), + thr, SLOT(onRefreshItems()), + Qt::QueuedConnection); + + // move the thread exec handler + // into its own context + thr->moveToThread(thr); +} + +static void cleanup() +{ + static bool terminated = false; + + if (terminated) { + // don't call it twice + return; + } + + terminated = true; + + MonitorItemThread::destruct(); //disconnects network + MainWindow::destruct(); //destroys the tray-icon + + if(app) { + delete app; + app = NULL; + } + + if (config) { + config->free_resources(); + free(config); + config = NULL; + } + + WSACleanup(); /* Cleanup Windows sockets */ +} + +void intHandler(int) +{ + exit(0); +} + +static void init_environment(int argc, char* argv[]) +{ + setlocale(LC_ALL, ""); + bindtextdomain("bareos", LOCALEDIR); + textdomain("bareos"); + + init_stack_dump(); + my_name_is(argc, argv, "tray-monitor"); + init_msg(NULL, NULL); + signal(SIGINT, intHandler); + working_directory = "/tmp"; + WSA_Init(); /* Initialize Windows sockets */ +} + +/********************************************************************* + * + * Main Bareos Tray Monitor -- User Interface Program + * + */ +int main(int argc, char *argv[]) +{ + init_environment(argc, argv); + + cl_opts cl; // remember some command line options + parse_command_line(argc, argv, cl); + + // read the config file + config = new_config_parser(); + parse_tmon_config(config, cl.configfile, M_ERROR_TERM); + + // this is the Qt core application + // with its message handler + app = new QApplication(argc, argv); + app->setQuitOnLastWindowClosed(false); + + setupQtObjects(); + + // create the monitoritems + QStringList tabRefs = MonitorItemThread::instance()->createRes(cl); + MainWindow::instance()->addTabs(tabRefs); + + // exit() if it was only a test + if (cl.test_config_only) { + exit(0); + } + + MonitorItemThread::instance()->start(); + + // launch the QApplication message handler + int ret = app->exec(); + + // cleanup everything before finishing + cleanup(); + + return ret; +} +/* This is a replacement for the std::exit() handler */ +void exit(int status) +{ + /* avoid to call the std::exit() cleanup handlers + * via atexit() since exit() destroys objects that + * are used by the QApplication class and this would + * lead to a sementation fault when QApplication + * in turn wants to destroy its child-objects. */ + + // first do the Qt cleanup + cleanup(); + + // do the kernel cleanup + _exit(status); +} diff --git a/src/qt-tray-monitor/tray-monitor.h b/src/qt-tray-monitor/tray-monitor.h new file mode 100644 index 00000000000..d0ba5df7d49 --- /dev/null +++ b/src/qt-tray-monitor/tray-monitor.h @@ -0,0 +1,48 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2004-2011 Free Software Foundation Europe e.V. + Copyright (C) 2011-2012 Planets Communications B.V. + Copyright (C) 2013-2013 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ +/* + * Includes specific to the tray monitor + * + * Nicolas Boichat, August MMIV + */ + +#ifndef TRAY_MONITOR_H +#define TRAY_MONITOR_H + +struct cl_opts +{ + char *configfile; + bool test_config_only; + cl_opts () { + configfile = (char*)0; + test_config_only = false; + } +}; + +class MonitorItem; +class MONITORRES; + +void refresh_item(); +const MONITORRES* getMonitor(); + +#endif /* TRAY_MONITOR_H */ diff --git a/src/qt-console/tray-monitor/tray-monitor.pro.in b/src/qt-tray-monitor/tray-monitor.pro.in similarity index 79% rename from src/qt-console/tray-monitor/tray-monitor.pro.in rename to src/qt-tray-monitor/tray-monitor.pro.in index 444989296d5..020f82074f6 100644 --- a/src/qt-console/tray-monitor/tray-monitor.pro.in +++ b/src/qt-tray-monitor/tray-monitor.pro.in @@ -15,7 +15,7 @@ CONFIG( debug, debug|release ) { CONFIG += release } -LIBS += -L../../lib -lbareoscfg -lbareos -L../../findlib -lbareosfind @OPENSSL_LIBS@ +LIBS += -L../lib -lbareoscfg -lbareos bins.path = /$(DESTDIR)@sbindir@ bins.files = bareos-tray-monitor @@ -31,7 +31,7 @@ autostarts.files = bareos-tray-monitor.desktop TEMPLATE = app TARGET = bareos-tray-monitor DEPENDPATH += . -INCLUDEPATH += ../.. ../../include . +INCLUDEPATH += ../include .. . LIBTOOL_LINK = @QMAKE_LIBTOOL@ --silent --tag=CXX --mode=link LIBTOOL_INSTALL = @QMAKE_LIBTOOL@ --silent --mode=install @@ -39,16 +39,16 @@ QMAKE_LINK = $${LIBTOOL_LINK} $(CXX) QMAKE_INSTALL_PROGRAM = $${LIBTOOL_INSTALL} install -m @SBINPERM@ -p QMAKE_CLEAN += .libs/* bareos-tray-monitor release/bareos-tray-monitor -RESOURCES = ../main.qrc +RESOURCES = main.qrc MOC_DIR = moc OBJECTS_DIR = obj UI_DIR = ui # Main directory -HEADERS += tray_conf.h tray-monitor.h tray-ui.h -SOURCES += authenticate.cpp tray_conf.cpp tray-monitor.cpp +HEADERS += tray_conf.h tray-monitor.h traymenu.h systemtrayicon.h mainwindow.h authenticate.h monitoritem.h monitoritemthread.h +SOURCES += authenticate.cpp tray_conf.cpp tray-monitor.cpp traymenu.cpp systemtrayicon.cpp mainwindow.cpp monitoritem.cpp monitoritemthread.cpp -FORMS += ../run/run.ui +FORMS += mainwindow.ui INSTALLS += bins confs icons desktopentries autostarts diff --git a/src/qt-console/tray-monitor/tray_conf.cpp b/src/qt-tray-monitor/tray_conf.cpp similarity index 97% rename from src/qt-console/tray-monitor/tray_conf.cpp rename to src/qt-tray-monitor/tray_conf.cpp index f688075aa47..40a9f43df03 100644 --- a/src/qt-console/tray-monitor/tray_conf.cpp +++ b/src/qt-tray-monitor/tray_conf.cpp @@ -2,6 +2,8 @@ BAREOS® - Backup Archiving REcovery Open Sourced Copyright (C) 2004-2011 Free Software Foundation Europe e.V. + Copyright (C) 2011-2012 Planets Communications B.V. + Copyright (C) 2013-2013 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -236,6 +238,11 @@ void free_resource(RES *sres, int type) switch (type) { case R_MONITOR: break; + case R_DIRECTOR: + if (res->res_dir.address) { + free(res->res_dir.address); + } + break; case R_CLIENT: if (res->res_client.address) { free(res->res_client.address); @@ -288,7 +295,7 @@ void save_resource(int type, RES_ITEM *items, int pass) /* * Ensure that all required items are present */ - for (i=0; items[i].name; i++) { + for (i = 0; items[i].name; i++) { if (items[i].flags & ITEM_REQUIRED) { if (!bit_is_set(i, res_all.res_monitor.hdr.item_present)) { Emsg2(M_ERROR_TERM, 0, _("%s item is required in %s resource, but not found.\n"), @@ -378,7 +385,7 @@ void save_resource(int type, RES_ITEM *items, int pass) /* * Add new res to end of chain */ - for (last=next=res_head[rindex]; next; next=next->next) { + for (last = next = res_head[rindex]; next; next=next->next) { last = next; if (strcmp(next->name, res->res_monitor.hdr.name) == 0) { Emsg2(M_ERROR_TERM, 0, diff --git a/src/qt-console/tray-monitor/tray_conf.h b/src/qt-tray-monitor/tray_conf.h similarity index 93% rename from src/qt-console/tray-monitor/tray_conf.h rename to src/qt-tray-monitor/tray_conf.h index d786d709b83..6ff1baa8533 100644 --- a/src/qt-console/tray-monitor/tray_conf.h +++ b/src/qt-tray-monitor/tray_conf.h @@ -1,9 +1,7 @@ /* BAREOS® - Backup Archiving REcovery Open Sourced - Copyright (C) 2004-2007 Free Software Foundation Europe e.V. - Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2013 Bareos GmbH & Co. KG + Copyright (C) 2004-2011 Free Software Foundation Europe e.V. This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -33,7 +31,12 @@ /* * Resource codes -- they must be sequential for indexing */ -enum rescode { + +#ifndef TRAY_CONF_H_INCLUDED +#define TRAY_CONF_H_INCLUDED + +enum Rescode { + R_UNKNOWN = 0, R_MONITOR = 1001, R_DIRECTOR, R_CLIENT, @@ -125,3 +128,5 @@ union URES { CONFONTRES con_font; RES hdr; }; + +#endif /* TRAY_CONF_H_INCLUDED */ diff --git a/src/qt-tray-monitor/traymenu.cpp b/src/qt-tray-monitor/traymenu.cpp new file mode 100644 index 00000000000..9e2ef06f8d7 --- /dev/null +++ b/src/qt-tray-monitor/traymenu.cpp @@ -0,0 +1,63 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2013-2013 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#include "traymenu.h" + +#include +#include +#include +#include + +TrayMenu::TrayMenu(QWidget* mainWindow) + : QMenu(mainWindow) +{ + setObjectName("TrayMenu"); + + createAction("Display", "Display", mainWindow); + createAction("About", "About", mainWindow); + addSeparator(); + createAction("Quit", "Quit", mainWindow); +} + +TrayMenu::~TrayMenu() +{ + return; +} + +void TrayMenu::createAction(QString objName, QString text, QWidget* mainWindow) +{ + const QString& translate = QApplication::translate("TrayMonitor", + text.toUtf8(), + 0, + QApplication::UnicodeUTF8); + + QAction *action = new QAction(translate, mainWindow); + + /* QActions are connected to the mainWindow with their + * name-signals-schema i.e. "on_Display_triggered()" + * using QMetaObject::connectSlotsByName(mainWindow) + * during SetupUi of the mainWindow */ + + const QString& objNameForSignal = QString("TrayMenu_%1").arg(objName); + action->setObjectName(objNameForSignal); + + addAction(action); +} diff --git a/src/qt-tray-monitor/traymenu.h b/src/qt-tray-monitor/traymenu.h new file mode 100644 index 00000000000..6df7ce7152d --- /dev/null +++ b/src/qt-tray-monitor/traymenu.h @@ -0,0 +1,45 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2013-2013 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#ifndef TRAYMONITOR_TRAYMENU_H +#define TRAYMONITOR_TRAYMENU_H + +#include +#include + +class QAction; + +class TrayMenu : public QMenu +{ + Q_OBJECT + +public: + TrayMenu(QWidget* trayMonitor = 0); + virtual ~TrayMenu(); + +private: + void createAction(QString objName, QString text, QWidget* trayMonitor); + +public slots: +signals: +}; + +#endif // TRAYMONITOR_TRAYMENU_H diff --git a/src/win32/Makefile.inc b/src/win32/Makefile.inc index 01301faef6a..f7def87bce2 100644 --- a/src/win32/Makefile.inc +++ b/src/win32/Makefile.inc @@ -17,11 +17,13 @@ MINGW_64_BASE = /usr/x86_64-w64-mingw32 ifeq ($(WIN_VERSION),32) QMAKE = /usr/bin/i686-w64-mingw32-qmake +WINDRES = /usr/bin/i686-w64-mingw32-windres CXX = /usr/bin/i686-w64-mingw32-g++ CXXFLAGS = $(DEFINES) $(INCLUDES) -Wall -m$(WIN_VERSION) -mwin32 -mthreads -O3 -fno-strict-aliasing -Wno-unknown-pragmas MINGW_LIB = $(MINGW_32_BASE)/sys-root/mingw/lib else QMAKE = /usr/bin/x86_64-w64-mingw32-qmake +WINDRES = /usr/bin/x86_64-w64-mingw32-windres CXX = /usr/bin/x86_64-w64-mingw32-g++ CXXFLAGS = $(DEFINES) $(INCLUDES) -Wall -m$(WIN_VERSION) -mwin32 -mthreads -O3 -fno-strict-aliasing -Wno-unknown-pragmas MINGW_LIB = $(MINGW_64_BASE)/sys-root/mingw/lib diff --git a/src/win32/filed/Makefile b/src/win32/filed/Makefile index d43fcfe066b..e49b981ce22 100644 --- a/src/win32/filed/Makefile +++ b/src/win32/filed/Makefile @@ -36,11 +36,15 @@ SVRSRCS = accurate.c authenticate.c backup.c compression.c \ service.c main.c SVROBJS = $(SVRSRCS:.c=.o) +WINDRESSRCS = icon.rc +WINDRESOBJS = $(WINDRESSRCS:.rc=.o) + + all: bareos-fd.exe bareos-fd.exe: DLL_USAGE = -DUSING_DLL -bareos-fd.exe: $(SVROBJS) - $(CXX) $(LDFLAGS_WINAPP) $(SVROBJS) $(LDLIBS) -o $@ +bareos-fd.exe: $(SVROBJS) $(WINDRESOBJS) + $(CXX) $(LDFLAGS_WINAPP) $(SVROBJS) $(WINDRESOBJS) $(LDLIBS) -o $@ clean: rm -f *.o @@ -52,3 +56,7 @@ distclean:: clean .c.o: @echo "Compiling $<" $(CXX) $(DLL_USAGE) $(CXXFLAGS) -c -o $@ $< + +%.o : %.rc + @echo "Ressource Compiling $^" + $(WINDRES) $^ -o $@ diff --git a/src/win32/filed/icon.rc b/src/win32/filed/icon.rc new file mode 100644 index 00000000000..7066563cbc8 --- /dev/null +++ b/src/win32/filed/icon.rc @@ -0,0 +1,25 @@ +id ICON "../../../platforms/win32/bareos.ico" +1 VERSIONINFO +FILEVERSION 1,0,0,0 +PRODUCTVERSION 1,0,0,0 +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "080904E4" + BEGIN + VALUE "CompanyName", "Bareos GmbH & Co. KG" + VALUE "FileDescription", "Bareos File Daemon" + VALUE "FileVersion", "12.4.2" + VALUE "InternalName", "bareos-fd.exe" + VALUE "LegalCopyright", "See LICENSE File" + VALUE "OriginalFilename", "bareos-fd.exe" + VALUE "ProductName", "Bareos File Daemon" + VALUE "ProductVersion", "12.4.2" + END + END + + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x809, 1252 + END +END diff --git a/src/win32/qt-console/bat.pro b/src/win32/qt-console/bat.pro index e70b8b2b628..be798795167 100644 --- a/src/win32/qt-console/bat.pro +++ b/src/win32/qt-console/bat.pro @@ -18,7 +18,7 @@ DEPENDPATH += . INCLUDEPATH += ../.. ../../include ../include ../compat/include ../../qt-console VPATH = ../../qt-console -LIBS += -mwindows ../lib/libbareos.a ../lib/libbareos.dll ../findlib/libbareosfind.dll -lwsock32 +LIBS += -mwindows ../lib/libbareos.a ../lib/libbareos.dll -lwsock32 DEFINES += HAVE_WIN32 HAVE_MINGW RESOURCES = main.qrc diff --git a/src/win32/qt-tray-monitor/tray-monitor.pro b/src/win32/qt-tray-monitor/tray-monitor.pro index 37cb3214c2e..b912d0fc7e8 100644 --- a/src/win32/qt-tray-monitor/tray-monitor.pro +++ b/src/win32/qt-tray-monitor/tray-monitor.pro @@ -14,20 +14,26 @@ confs.commands = ./install_conf_file TEMPLATE = app TARGET = bareos-tray-monitor +PRE_TARGETDEPS += ../lib/libbareos.a ../lib/libbareos.dll DEPENDPATH += . -INCLUDEPATH += ../.. ../../include ../include ../compat/include ../../qt-console/tray-monitor ../qt-console -VPATH = ../../qt-console/tray-monitor ../../qt-console +INCLUDEPATH += ../.. ../../include ../include ../compat/include \ + ../../qt-tray-monitor +VPATH = ../../qt-tray-monitor -LIBS += -mwindows ../lib/libbareos.a ../lib/libbareos.dll ../findlib/libbareosfind.dll -lwsock32 -DEFINES += HAVE_WIN32 HAVE_MINGW +LIBS += -mwindows ../lib/libbareos.a ../lib/libbareos.dll -lwsock32 +DEFINES += HAVE_WIN32 HAVE_MINGW _STAT_DEFINED=1 -RESOURCES = ../main.qrc +RESOURCES = main.qrc MOC_DIR = moc OBJECTS_DIR = obj UI_DIR = ui # Main directory -HEADERS += tray_conf.h tray-monitor.h tray-ui.h -SOURCES += authenticate.cpp tray_conf.cpp tray-monitor.cpp +HEADERS += tray_conf.h tray-monitor.h traymenu.h \ + systemtrayicon.h mainwindow.h authenticate.h monitoritem.h \ + monitoritemthread.h monitortab.h +SOURCES += authenticate.cpp tray_conf.cpp tray-monitor.cpp \ + traymenu.cpp systemtrayicon.cpp mainwindow.cpp monitoritem.cpp \ + monitoritemthread.cpp -FORMS += ../run/run.ui +FORMS += mainwindow.ui