Browse Source

Add restart button to connection menus

- This works the same way as restart button in the status window
  but is more conveniently accessible from the tray menu.

Signed-off-by: Selva Nair <selva.nair@gmail.com>
pull/188/head
Selva Nair 8 years ago
parent
commit
31896ce33b
  1. 3
      main.c
  2. 1
      openvpn-gui-res.h
  3. 20
      openvpn.c
  4. 1
      openvpn.h
  5. 1
      res/openvpn-gui-res-en.rc
  6. 8
      tray.c
  7. 1
      tray.h

3
main.c

@ -394,6 +394,9 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
if ( (LOWORD(wParam) >= IDM_DISCONNECTMENU) && (LOWORD(wParam) < IDM_DISCONNECTMENU + MAX_CONFIGS) ) {
StopOpenVPN(&o.conn[LOWORD(wParam) - IDM_DISCONNECTMENU]);
}
if ( (LOWORD(wParam) >= IDM_RECONNECTMENU) && (LOWORD(wParam) < IDM_RECONNECTMENU + MAX_CONFIGS) ) {
RestartOpenVPN(&o.conn[LOWORD(wParam) - IDM_RECONNECTMENU]);
}
if ( (LOWORD(wParam) >= IDM_STATUSMENU) && (LOWORD(wParam) < IDM_STATUSMENU + MAX_CONFIGS) ) {
ShowWindow(o.conn[LOWORD(wParam) - IDM_STATUSMENU].hwndStatus, SW_SHOW);
}

1
openvpn-gui-res.h

@ -149,6 +149,7 @@
#define IDS_MENU_ASK_STOP_SERVICE 1022
#define IDS_MENU_IMPORT 1023
#define IDS_MENU_CLEARPASS 1024
#define IDS_MENU_RECONNECT 1025
/* LogViewer Dialog */
#define IDS_ERR_START_LOG_VIEWER 1101

20
openvpn.c

@ -52,6 +52,7 @@
#define WM_OVPN_STOP (WM_APP + 10)
#define WM_OVPN_SUSPEND (WM_APP + 11)
#define WM_OVPN_RESTART (WM_APP + 12)
extern options_t o;
@ -1565,7 +1566,7 @@ StatusDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
case ID_RESTART:
c->state = reconnecting;
SetFocus(GetDlgItem(c->hwndStatus, ID_EDT_LOG));
ManagementCommand(c, "signal SIGHUP", NULL, regular);
RestartOpenVPN(c);
return TRUE;
}
break;
@ -1628,6 +1629,18 @@ StatusDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
KillTimer (hwndDlg, IDT_STOP_TIMER);
}
break;
case WM_OVPN_RESTART:
c = (connection_t *) GetProp(hwndDlg, cfgProp);
/* external messages can trigger when we are not ready -- check the state */
if (IsWindowEnabled(GetDlgItem(c->hwndStatus, ID_RESTART)))
ManagementCommand(c, "signal SIGHUP", NULL, regular);
if (!o.silent_connection)
{
SetForegroundWindow(c->hwndStatus);
ShowWindow(c->hwndStatus, SW_SHOW);
}
break;
}
return FALSE;
}
@ -1955,6 +1968,11 @@ SuspendOpenVPN(int config)
PostMessage(o.conn[config].hwndStatus, WM_OVPN_SUSPEND, 0, 0);
}
void
RestartOpenVPN(connection_t *c)
{
PostMessage(c->hwndStatus, WM_OVPN_RESTART, 0, 0);
}
void
SetStatusWinIcon(HWND hwndDlg, int iconId)

1
openvpn.h

@ -26,6 +26,7 @@
BOOL StartOpenVPN(connection_t *);
void StopOpenVPN(connection_t *);
void SuspendOpenVPN(int config);
void RestartOpenVPN(connection_t *);
BOOL CheckVersion();
void SetStatusWinIcon(HWND hwndDlg, int IconID);

1
res/openvpn-gui-res-en.rc

@ -247,6 +247,7 @@ BEGIN
IDS_MENU_CLOSE "Exit"
IDS_MENU_CONNECT "Connect"
IDS_MENU_DISCONNECT "Disconnect"
IDS_MENU_RECONNECT "Reconnect"
IDS_MENU_STATUS "Show Status"
IDS_MENU_VIEWLOG "View Log"
IDS_MENU_EDITCONFIG "Edit Config"

8
tray.c

@ -63,6 +63,7 @@ CreatePopupMenus()
if (o.service_only == 0) {
AppendMenu(hMenu, MF_STRING, IDM_CONNECTMENU, LoadLocalizedString(IDS_MENU_CONNECT));
AppendMenu(hMenu, MF_STRING, IDM_DISCONNECTMENU, LoadLocalizedString(IDS_MENU_DISCONNECT));
AppendMenu(hMenu, MF_STRING, IDM_RECONNECTMENU, LoadLocalizedString(IDS_MENU_RECONNECT));
AppendMenu(hMenu, MF_STRING, IDM_STATUSMENU, LoadLocalizedString(IDS_MENU_STATUS));
AppendMenu(hMenu, MF_SEPARATOR, 0, 0);
}
@ -117,6 +118,7 @@ CreatePopupMenus()
if (o.service_only == 0) {
AppendMenu(hMenuConn[i], MF_STRING, IDM_CONNECTMENU + i, LoadLocalizedString(IDS_MENU_CONNECT));
AppendMenu(hMenuConn[i], MF_STRING, IDM_DISCONNECTMENU + i, LoadLocalizedString(IDS_MENU_DISCONNECT));
AppendMenu(hMenuConn[i], MF_STRING, IDM_RECONNECTMENU + i, LoadLocalizedString(IDS_MENU_RECONNECT));
AppendMenu(hMenuConn[i], MF_STRING, IDM_STATUSMENU + i, LoadLocalizedString(IDS_MENU_STATUS));
AppendMenu(hMenuConn[i], MF_SEPARATOR, 0, 0);
}
@ -349,18 +351,21 @@ SetMenuStatus(connection_t *c, conn_state_t state)
{
EnableMenuItem(hMenu, IDM_CONNECTMENU, MF_ENABLED);
EnableMenuItem(hMenu, IDM_DISCONNECTMENU, MF_GRAYED);
EnableMenuItem(hMenu, IDM_RECONNECTMENU, MF_GRAYED);
EnableMenuItem(hMenu, IDM_STATUSMENU, MF_GRAYED);
}
else if (state == connecting || state == resuming || state == connected)
{
EnableMenuItem(hMenu, IDM_CONNECTMENU, MF_GRAYED);
EnableMenuItem(hMenu, IDM_DISCONNECTMENU, MF_ENABLED);
EnableMenuItem(hMenu, IDM_RECONNECTMENU, MF_ENABLED);
EnableMenuItem(hMenu, IDM_STATUSMENU, MF_ENABLED);
}
else if (state == disconnecting)
{
EnableMenuItem(hMenu, IDM_CONNECTMENU, MF_GRAYED);
EnableMenuItem(hMenu, IDM_DISCONNECTMENU, MF_GRAYED);
EnableMenuItem(hMenu, IDM_RECONNECTMENU, MF_GRAYED);
EnableMenuItem(hMenu, IDM_STATUSMENU, MF_ENABLED);
}
if (c->flags & (FLAG_SAVE_AUTH_PASS | FLAG_SAVE_KEY_PASS))
@ -384,18 +389,21 @@ SetMenuStatus(connection_t *c, conn_state_t state)
{
EnableMenuItem(hMenuConn[i], IDM_CONNECTMENU + i, MF_ENABLED);
EnableMenuItem(hMenuConn[i], IDM_DISCONNECTMENU + i, MF_GRAYED);
EnableMenuItem(hMenuConn[i], IDM_RECONNECTMENU + i, MF_GRAYED);
EnableMenuItem(hMenuConn[i], IDM_STATUSMENU + i, MF_GRAYED);
}
else if (state == connecting || state == resuming || state == connected)
{
EnableMenuItem(hMenuConn[i], IDM_CONNECTMENU + i, MF_GRAYED);
EnableMenuItem(hMenuConn[i], IDM_DISCONNECTMENU + i, MF_ENABLED);
EnableMenuItem(hMenuConn[i], IDM_RECONNECTMENU + i, MF_ENABLED);
EnableMenuItem(hMenuConn[i], IDM_STATUSMENU + i, MF_ENABLED);
}
else if (state == disconnecting)
{
EnableMenuItem(hMenuConn[i], IDM_CONNECTMENU + i, MF_GRAYED);
EnableMenuItem(hMenuConn[i], IDM_DISCONNECTMENU + i, MF_GRAYED);
EnableMenuItem(hMenuConn[i], IDM_RECONNECTMENU + i, MF_GRAYED);
EnableMenuItem(hMenuConn[i], IDM_STATUSMENU + i, MF_ENABLED);
}
if (c->flags & (FLAG_SAVE_AUTH_PASS | FLAG_SAVE_KEY_PASS))

1
tray.h

@ -42,6 +42,7 @@
#define IDM_EDITMENU (MAX_CONFIGS + IDM_VIEWLOGMENU)
#define IDM_PASSPHRASEMENU (MAX_CONFIGS + IDM_EDITMENU)
#define IDM_CLEARPASSMENU (MAX_CONFIGS + IDM_PASSPHRASEMENU)
#define IDM_RECONNECTMENU (MAX_CONFIGS + IDM_CLEARPASSMENU)
void CreatePopupMenus();
void OnNotifyTray(LPARAM);

Loading…
Cancel
Save