diff options
author | Daniel P. Berrange <berrange@redhat.com> | 2012-01-31 15:01:08 +0000 |
---|---|---|
committer | Daniel P. Berrange <berrange@redhat.com> | 2012-02-06 12:40:09 +0000 |
commit | e1283a9a60ef55f2e18d53e830874c76db526d66 (patch) | |
tree | 55d495d5cab4acc6a213662bb7d208610ab0c130 | |
parent | c67a8cfdbed878674f0c15c5f40b88cccedf391a (diff) |
Convert TABS to spaces & reindent everywhere
38 files changed, 4500 insertions, 4474 deletions
@@ -3,7 +3,7 @@ set -e srcdir=`dirname $0` -test -z "$srcdir" && srcdir=. +test -z "$srcdir" && srcdir=. THEDIR=`pwd` cd $srcdir @@ -11,23 +11,23 @@ cd $srcdir DIE=0 (autoconf --version) < /dev/null > /dev/null 2>&1 || { - echo - echo "You must have autoconf installed to compile virt-viewer." - echo "Download the appropriate package for your distribution," - echo "or see http://www.gnu.org/software/autoconf" - DIE=1 + echo + echo "You must have autoconf installed to compile virt-viewer." + echo "Download the appropriate package for your distribution," + echo "or see http://www.gnu.org/software/autoconf" + DIE=1 } (automake --version) < /dev/null > /dev/null 2>&1 || { - echo - DIE=1 - echo "You must have automake installed to compile virt-viewer." - echo "Download the appropriate package for your distribution," - echo "or see http://www.gnu.org/software/automake" + echo + DIE=1 + echo "You must have automake installed to compile virt-viewer." + echo "Download the appropriate package for your distribution," + echo "or see http://www.gnu.org/software/automake" } if test "$DIE" -eq 1; then - exit 1 + exit 1 fi EXTRA_ARGS="" @@ -38,7 +38,7 @@ if test "x$1" = "x--system"; then sysconfdir=/etc localstatedir=/var if [ -d /usr/lib64 ]; then - libdir=$prefix/lib64 + libdir=$prefix/lib64 fi EXTRA_ARGS="--prefix=$prefix --sysconfdir=$sysconfdir --localstatedir=$localstatedir --libdir=$libdir" echo "Running ./configure with $EXTRA_ARGS $@" @@ -59,6 +59,6 @@ autoconf cd $THEDIR $srcdir/configure $EXTRA_ARGS "$@" && { - echo + echo echo "Now type 'make' to compile virt-viewer." } diff --git a/plugin/npshell.c b/plugin/npshell.c index ccd11a5..d85739c 100644 --- a/plugin/npshell.c +++ b/plugin/npshell.c @@ -46,8 +46,8 @@ * This file defines a "shell" plugin that plugin developers can use * as the basis for a real plugin. This shell just provides empty * implementations of all functions that the plugin can implement - * that will be called by Netscape (the NPP_xxx methods defined in - * npapi.h). + * that will be called by Netscape (the NPP_xxx methods defined in + * npapi.h). * * dp Suresh <dp@netscape.com> * updated 5/1998 <pollmann@netscape.com> @@ -59,11 +59,11 @@ /* The contents of this file are subject to the Mozilla Public License -Version 1.1 (the "License"); you may not use this file except in compliance +Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ -Software distributed under the License is distributed on an "AS IS" basis, -WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +Software distributed under the License is distributed on an "AS IS" basis, +WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is stub code that defines the binary interface to a Mozilla @@ -147,7 +147,7 @@ NPP_Shutdown(void) debug ("NPP_Shutdown"); } -NPError +NPError NPP_New(NPMIMEType pluginType G_GNUC_UNUSED, NPP instance, uint16 mode, @@ -220,7 +220,7 @@ NPP_New(NPMIMEType pluginType G_GNUC_UNUSED, return NPERR_NO_ERROR; } -NPError +NPError NPP_Destroy(NPP instance, NPSavedData** save G_GNUC_UNUSED) { PluginInstance* This; @@ -245,7 +245,7 @@ NPP_Destroy(NPP instance, NPSavedData** save G_GNUC_UNUSED) } -NPError +NPError NPP_SetWindow(NPP instance, NPWindow* window) { debug ("NPP_SetWindow"); @@ -253,7 +253,7 @@ NPP_SetWindow(NPP instance, NPWindow* window) return VirtViewerXSetWindow(instance, window); } -int32 +int32 NPP_WriteReady(NPP instance, NPStream *stream) { /*printf("NPP_WriteReady()\n");*/ @@ -267,7 +267,7 @@ NPP_WriteReady(NPP instance, NPStream *stream) return -1L; /* don't accept any bytes in NPP_Write() */ } -int32 +int32 NPP_Write(NPP instance, NPStream *stream, int32 offset G_GNUC_UNUSED, int32 len G_GNUC_UNUSED, void *buffer G_GNUC_UNUSED) @@ -282,7 +282,7 @@ NPP_Write(NPP instance, NPStream *stream, return -1L; /* don't accept any bytes in NPP_Write() */ } -NPError +NPError NPP_DestroyStream(NPP instance, NPStream *stream G_GNUC_UNUSED, NPError reason G_GNUC_UNUSED) { @@ -298,7 +298,7 @@ NPP_DestroyStream(NPP instance, NPStream *stream G_GNUC_UNUSED, return NPERR_NO_ERROR; } -void +void NPP_StreamAsFile(NPP instance G_GNUC_UNUSED, NPStream *stream G_GNUC_UNUSED, const char* fname G_GNUC_UNUSED) { @@ -323,7 +323,7 @@ NPP_URLNotify(NPP instance G_GNUC_UNUSED, const char* url G_GNUC_UNUSED, } -void +void NPP_Print(NPP instance, NPPrint* printInfo) { /*printf("NPP_Print()\n");*/ @@ -334,7 +334,7 @@ NPP_Print(NPP instance, NPPrint* printInfo) /***** Insert NPP_Print code here *****\ PluginInstance* This = (PluginInstance*) instance->pdata; \**************************************/ - + if (printInfo->mode == NP_FULL) { /* * PLUGIN DEVELOPERS: @@ -359,7 +359,7 @@ NPP_Print(NPP instance, NPPrint* printInfo) NPBool printOne = printInfo->print.fullPrint.printOne; \**************************************/ - + /* Do the default*/ printInfo->print.fullPrint.pluginPrinted = FALSE; } diff --git a/plugin/npunix.c b/plugin/npunix.c index ddc4bdf..48948d0 100644 --- a/plugin/npunix.c +++ b/plugin/npunix.c @@ -262,7 +262,7 @@ void NPN_PopPopupsEnabledState(NPP instance) * Wrapper functions : Netscape Navigator -> plugin * * These functions let the plugin developer just create the APIs - * as documented and defined in npapi.h, without needing to + * as documented and defined in npapi.h, without needing to * install those functions in the function table or worry about * setting up globals for 68K plugins. * @@ -275,7 +275,7 @@ Private_New(NPMIMEType pluginType, NPP instance, uint16 mode, NPError ret; PLUGINDEBUGSTR("New"); ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved); - return ret; + return ret; } static NPError @@ -344,7 +344,6 @@ Private_DestroyStream(NPP instance, NPStream* stream, NPError reason) static void Private_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData) - { PLUGINDEBUGSTR("URLNotify"); NPP_URLNotify(instance, url, reason, notifyData); @@ -353,8 +352,8 @@ Private_URLNotify(NPP instance, const char* url, static NPError Private_GetValue(void *instance, NPPVariable variable, void *result) { - NPError rv = NPP_GetValue(instance, variable, result); - return rv; + NPError rv = NPP_GetValue(instance, variable, result); + return rv; } static void @@ -377,13 +376,13 @@ Private_GetJavaClass(void) } #endif -static int16 +static int16 Private_HandleEvent(NPP instance, void* event) { return NPP_HandleEvent(instance, event); } -/*********************************************************************** +/*********************************************************************** * * These functions are located automagically by netscape. * @@ -436,12 +435,12 @@ NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs) NPError err = NPERR_NO_ERROR; PLUGINDEBUGSTR("NP_Initialize"); - + /* validate input parameters */ if ((nsTable == NULL) || (pluginFuncs == NULL)) err = NPERR_INVALID_FUNCTABLE_ERROR; - + /* * Check the major version passed in Netscape's function table. * We won't load if the major version is newer than what we expect. @@ -456,11 +455,10 @@ NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs) err = NPERR_INCOMPATIBLE_VERSION_ERROR; if (nsTable->size < sizeof(NPNetscapeFuncs)) err = NPERR_INVALID_FUNCTABLE_ERROR; - if (pluginFuncs->size < sizeof(NPPluginFuncs)) + if (pluginFuncs->size < sizeof(NPPluginFuncs)) err = NPERR_INVALID_FUNCTABLE_ERROR; } - - + if (err == NPERR_NO_ERROR) { /* * Copy all the fields of Netscape function table into our @@ -519,7 +517,7 @@ NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs) err = NPP_Initialize(); } - + return err; } diff --git a/plugin/npupp.h b/plugin/npupp.h index 94712da..0240e31 100644 --- a/plugin/npupp.h +++ b/plugin/npupp.h @@ -68,117 +68,117 @@ typedef void* JRIGlobalRef; /****************************************************************************************** plug-in function table macros - for each function in and out of the plugin API we define + for each function in and out of the plugin API we define typedef NPP_FooUPP - #define NewNPP_FooProc - #define CallNPP_FooProc + #define NewNPP_FooProc + #define CallNPP_FooProc *******************************************************************************************/ /* NPP_Initialize */ typedef void (* NP_LOADDS NPP_InitializeUPP)(void); -#define NewNPP_InitializeProc(FUNC) \ - ((NPP_InitializeUPP) (FUNC)) -#define CallNPP_InitializeProc(FUNC) \ - (*(FUNC))() +#define NewNPP_InitializeProc(FUNC) \ + ((NPP_InitializeUPP) (FUNC)) +#define CallNPP_InitializeProc(FUNC) \ + (*(FUNC))() /* NPP_Shutdown */ typedef void (* NP_LOADDS NPP_ShutdownUPP)(void); -#define NewNPP_ShutdownProc(FUNC) \ - ((NPP_ShutdownUPP) (FUNC)) -#define CallNPP_ShutdownProc(FUNC) \ - (*(FUNC))() +#define NewNPP_ShutdownProc(FUNC) \ + ((NPP_ShutdownUPP) (FUNC)) +#define CallNPP_ShutdownProc(FUNC) \ + (*(FUNC))() /* NPP_New */ -typedef NPError (* NP_LOADDS NPP_NewUPP)(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved); -#define NewNPP_NewProc(FUNC) \ - ((NPP_NewUPP) (FUNC)) -#define CallNPP_NewProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) \ - (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6), (ARG7)) +typedef NPError (* NP_LOADDS NPP_NewUPP)(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved); +#define NewNPP_NewProc(FUNC) \ + ((NPP_NewUPP) (FUNC)) +#define CallNPP_NewProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6), (ARG7)) /* NPP_Destroy */ -typedef NPError (* NP_LOADDS NPP_DestroyUPP)(NPP instance, NPSavedData** save); -#define NewNPP_DestroyProc(FUNC) \ - ((NPP_DestroyUPP) (FUNC)) -#define CallNPP_DestroyProc(FUNC, ARG1, ARG2) \ - (*(FUNC))((ARG1), (ARG2)) +typedef NPError (* NP_LOADDS NPP_DestroyUPP)(NPP instance, NPSavedData** save); +#define NewNPP_DestroyProc(FUNC) \ + ((NPP_DestroyUPP) (FUNC)) +#define CallNPP_DestroyProc(FUNC, ARG1, ARG2) \ + (*(FUNC))((ARG1), (ARG2)) /* NPP_SetWindow */ -typedef NPError (* NP_LOADDS NPP_SetWindowUPP)(NPP instance, NPWindow* window); -#define NewNPP_SetWindowProc(FUNC) \ - ((NPP_SetWindowUPP) (FUNC)) -#define CallNPP_SetWindowProc(FUNC, ARG1, ARG2) \ - (*(FUNC))((ARG1), (ARG2)) +typedef NPError (* NP_LOADDS NPP_SetWindowUPP)(NPP instance, NPWindow* window); +#define NewNPP_SetWindowProc(FUNC) \ + ((NPP_SetWindowUPP) (FUNC)) +#define CallNPP_SetWindowProc(FUNC, ARG1, ARG2) \ + (*(FUNC))((ARG1), (ARG2)) /* NPP_NewStream */ -typedef NPError (* NP_LOADDS NPP_NewStreamUPP)(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype); -#define NewNPP_NewStreamProc(FUNC) \ - ((NPP_NewStreamUPP) (FUNC)) +typedef NPError (* NP_LOADDS NPP_NewStreamUPP)(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype); +#define NewNPP_NewStreamProc(FUNC) \ + ((NPP_NewStreamUPP) (FUNC)) #define CallNPP_NewStreamProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5) \ - (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5)) + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5)) /* NPP_DestroyStream */ -typedef NPError (* NP_LOADDS NPP_DestroyStreamUPP)(NPP instance, NPStream* stream, NPReason reason); -#define NewNPP_DestroyStreamProc(FUNC) \ - ((NPP_DestroyStreamUPP) (FUNC)) -#define CallNPP_DestroyStreamProc(FUNC, NPParg, NPStreamPtr, NPReasonArg) \ - (*(FUNC))((NPParg), (NPStreamPtr), (NPReasonArg)) +typedef NPError (* NP_LOADDS NPP_DestroyStreamUPP)(NPP instance, NPStream* stream, NPReason reason); +#define NewNPP_DestroyStreamProc(FUNC) \ + ((NPP_DestroyStreamUPP) (FUNC)) +#define CallNPP_DestroyStreamProc(FUNC, NPParg, NPStreamPtr, NPReasonArg) \ + (*(FUNC))((NPParg), (NPStreamPtr), (NPReasonArg)) /* NPP_WriteReady */ typedef int32 (* NP_LOADDS NPP_WriteReadyUPP)(NPP instance, NPStream* stream); -#define NewNPP_WriteReadyProc(FUNC) \ - ((NPP_WriteReadyUPP) (FUNC)) -#define CallNPP_WriteReadyProc(FUNC, NPParg, NPStreamPtr) \ - (*(FUNC))((NPParg), (NPStreamPtr)) +#define NewNPP_WriteReadyProc(FUNC) \ + ((NPP_WriteReadyUPP) (FUNC)) +#define CallNPP_WriteReadyProc(FUNC, NPParg, NPStreamPtr) \ + (*(FUNC))((NPParg), (NPStreamPtr)) /* NPP_Write */ typedef int32 (* NP_LOADDS NPP_WriteUPP)(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer); -#define NewNPP_WriteProc(FUNC) \ - ((NPP_WriteUPP) (FUNC)) -#define CallNPP_WriteProc(FUNC, NPParg, NPStreamPtr, offsetArg, lenArg, bufferPtr) \ - (*(FUNC))((NPParg), (NPStreamPtr), (offsetArg), (lenArg), (bufferPtr)) +#define NewNPP_WriteProc(FUNC) \ + ((NPP_WriteUPP) (FUNC)) +#define CallNPP_WriteProc(FUNC, NPParg, NPStreamPtr, offsetArg, lenArg, bufferPtr) \ + (*(FUNC))((NPParg), (NPStreamPtr), (offsetArg), (lenArg), (bufferPtr)) /* NPP_StreamAsFile */ typedef void (* NP_LOADDS NPP_StreamAsFileUPP)(NPP instance, NPStream* stream, const char* fname); -#define NewNPP_StreamAsFileProc(FUNC) \ - ((NPP_StreamAsFileUPP) (FUNC)) -#define CallNPP_StreamAsFileProc(FUNC, ARG1, ARG2, ARG3) \ - (*(FUNC))((ARG1), (ARG2), (ARG3)) +#define NewNPP_StreamAsFileProc(FUNC) \ + ((NPP_StreamAsFileUPP) (FUNC)) +#define CallNPP_StreamAsFileProc(FUNC, ARG1, ARG2, ARG3) \ + (*(FUNC))((ARG1), (ARG2), (ARG3)) /* NPP_Print */ typedef void (* NP_LOADDS NPP_PrintUPP)(NPP instance, NPPrint* platformPrint); -#define NewNPP_PrintProc(FUNC) \ - ((NPP_PrintUPP) (FUNC)) -#define CallNPP_PrintProc(FUNC, NPParg, NPPrintArg) \ - (*(FUNC))((NPParg), (NPPrintArg)) +#define NewNPP_PrintProc(FUNC) \ + ((NPP_PrintUPP) (FUNC)) +#define CallNPP_PrintProc(FUNC, NPParg, NPPrintArg) \ + (*(FUNC))((NPParg), (NPPrintArg)) /* NPP_HandleEvent */ typedef int16 (* NP_LOADDS NPP_HandleEventUPP)(NPP instance, void* event); -#define NewNPP_HandleEventProc(FUNC) \ - ((NPP_HandleEventUPP) (FUNC)) -#define CallNPP_HandleEventProc(FUNC, NPParg, voidPtr) \ - (*(FUNC))((NPParg), (voidPtr)) +#define NewNPP_HandleEventProc(FUNC) \ + ((NPP_HandleEventUPP) (FUNC)) +#define CallNPP_HandleEventProc(FUNC, NPParg, voidPtr) \ + (*(FUNC))((NPParg), (voidPtr)) /* NPP_URLNotify */ typedef void (* NP_LOADDS NPP_URLNotifyUPP)(NPP instance, const char* url, NPReason reason, void* notifyData); -#define NewNPP_URLNotifyProc(FUNC) \ - ((NPP_URLNotifyUPP) (FUNC)) -#define CallNPP_URLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ - (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4)) +#define NewNPP_URLNotifyProc(FUNC) \ + ((NPP_URLNotifyUPP) (FUNC)) +#define CallNPP_URLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4)) /* NPP_GetValue */ -typedef NPError (* NP_LOADDS NPP_GetValueUPP)(NPP instance, NPPVariable variable, void *ret_alue); -#define NewNPP_GetValueProc(FUNC) \ - ((NPP_GetValueUPP) (FUNC)) -#define CallNPP_GetValueProc(FUNC, ARG1, ARG2, ARG3) \ - (*(FUNC))((ARG1), (ARG2), (ARG3)) +typedef NPError (* NP_LOADDS NPP_GetValueUPP)(NPP instance, NPPVariable variable, void *ret_alue); +#define NewNPP_GetValueProc(FUNC) \ + ((NPP_GetValueUPP) (FUNC)) +#define CallNPP_GetValueProc(FUNC, ARG1, ARG2, ARG3) \ + (*(FUNC))((ARG1), (ARG2), (ARG3)) /* NPP_SetValue */ -typedef NPError (* NP_LOADDS NPP_SetValueUPP)(NPP instance, NPNVariable variable, void *ret_alue); -#define NewNPP_SetValueProc(FUNC) \ - ((NPP_SetValueUPP) (FUNC)) -#define CallNPP_SetValueProc(FUNC, ARG1, ARG2, ARG3) \ - (*(FUNC))((ARG1), (ARG2), (ARG3)) +typedef NPError (* NP_LOADDS NPP_SetValueUPP)(NPP instance, NPNVariable variable, void *ret_alue); +#define NewNPP_SetValueProc(FUNC) \ + ((NPP_SetValueUPP) (FUNC)) +#define CallNPP_SetValueProc(FUNC, ARG1, ARG2, ARG3) \ + (*(FUNC))((ARG1), (ARG2), (ARG3)) /* * Netscape entry points @@ -186,84 +186,84 @@ typedef NPError (* NP_LOADDS NPP_SetValueUPP)(NPP instance, NPNVariable variable /* NPN_GetValue */ -typedef NPError (* NP_LOADDS NPN_GetValueUPP)(NPP instance, NPNVariable variable, void *ret_alue); -#define NewNPN_GetValueProc(FUNC) \ - ((NPN_GetValueUPP) (FUNC)) -#define CallNPN_GetValueProc(FUNC, ARG1, ARG2, ARG3) \ - (*(FUNC))((ARG1), (ARG2), (ARG3)) +typedef NPError (* NP_LOADDS NPN_GetValueUPP)(NPP instance, NPNVariable variable, void *ret_alue); +#define NewNPN_GetValueProc(FUNC) \ + ((NPN_GetValueUPP) (FUNC)) +#define CallNPN_GetValueProc(FUNC, ARG1, ARG2, ARG3) \ + (*(FUNC))((ARG1), (ARG2), (ARG3)) /* NPN_SetValue */ -typedef NPError (* NP_LOADDS NPN_SetValueUPP)(NPP instance, NPPVariable variable, void *ret_alue); -#define NewNPN_SetValueProc(FUNC) \ - ((NPN_SetValueUPP) (FUNC)) -#define CallNPN_SetValueProc(FUNC, ARG1, ARG2, ARG3) \ - (*(FUNC))((ARG1), (ARG2), (ARG3)) +typedef NPError (* NP_LOADDS NPN_SetValueUPP)(NPP instance, NPPVariable variable, void *ret_alue); +#define NewNPN_SetValueProc(FUNC) \ + ((NPN_SetValueUPP) (FUNC)) +#define CallNPN_SetValueProc(FUNC, ARG1, ARG2, ARG3) \ + (*(FUNC))((ARG1), (ARG2), (ARG3)) /* NPN_GetUrlNotify */ -typedef NPError (* NP_LOADDS NPN_GetURLNotifyUPP)(NPP instance, const char* url, const char* window, void* notifyData); -#define NewNPN_GetURLNotifyProc(FUNC) \ - ((NPN_GetURLNotifyUPP) (FUNC)) -#define CallNPN_GetURLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ - (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4)) +typedef NPError (* NP_LOADDS NPN_GetURLNotifyUPP)(NPP instance, const char* url, const char* window, void* notifyData); +#define NewNPN_GetURLNotifyProc(FUNC) \ + ((NPN_GetURLNotifyUPP) (FUNC)) +#define CallNPN_GetURLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4)) /* NPN_PostUrlNotify */ typedef NPError (* NP_LOADDS NPN_PostURLNotifyUPP)(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData); -#define NewNPN_PostURLNotifyProc(FUNC) \ - ((NPN_PostURLNotifyUPP) (FUNC)) +#define NewNPN_PostURLNotifyProc(FUNC) \ + ((NPN_PostURLNotifyUPP) (FUNC)) #define CallNPN_PostURLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) \ - (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6), (ARG7)) + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6), (ARG7)) /* NPN_GetUrl */ -typedef NPError (* NP_LOADDS NPN_GetURLUPP)(NPP instance, const char* url, const char* window); -#define NewNPN_GetURLProc(FUNC) \ - ((NPN_GetURLUPP) (FUNC)) -#define CallNPN_GetURLProc(FUNC, ARG1, ARG2, ARG3) \ - (*(FUNC))((ARG1), (ARG2), (ARG3)) +typedef NPError (* NP_LOADDS NPN_GetURLUPP)(NPP instance, const char* url, const char* window); +#define NewNPN_GetURLProc(FUNC) \ + ((NPN_GetURLUPP) (FUNC)) +#define CallNPN_GetURLProc(FUNC, ARG1, ARG2, ARG3) \ + (*(FUNC))((ARG1), (ARG2), (ARG3)) /* NPN_PostUrl */ typedef NPError (* NP_LOADDS NPN_PostURLUPP)(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file); -#define NewNPN_PostURLProc(FUNC) \ - ((NPN_PostURLUPP) (FUNC)) +#define NewNPN_PostURLProc(FUNC) \ + ((NPN_PostURLUPP) (FUNC)) #define CallNPN_PostURLProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) \ - (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6)) + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6)) /* NPN_RequestRead */ -typedef NPError (* NP_LOADDS NPN_RequestReadUPP)(NPStream* stream, NPByteRange* rangeList); -#define NewNPN_RequestReadProc(FUNC) \ - ((NPN_RequestReadUPP) (FUNC)) -#define CallNPN_RequestReadProc(FUNC, stream, range) \ - (*(FUNC))((stream), (range)) +typedef NPError (* NP_LOADDS NPN_RequestReadUPP)(NPStream* stream, NPByteRange* rangeList); +#define NewNPN_RequestReadProc(FUNC) \ + ((NPN_RequestReadUPP) (FUNC)) +#define CallNPN_RequestReadProc(FUNC, stream, range) \ + (*(FUNC))((stream), (range)) /* NPN_NewStream */ -typedef NPError (* NP_LOADDS NPN_NewStreamUPP)(NPP instance, NPMIMEType type, const char* window, NPStream** stream); -#define NewNPN_NewStreamProc(FUNC) \ - ((NPN_NewStreamUPP) (FUNC)) -#define CallNPN_NewStreamProc(FUNC, npp, type, window, stream) \ - (*(FUNC))((npp), (type), (window), (stream)) +typedef NPError (* NP_LOADDS NPN_NewStreamUPP)(NPP instance, NPMIMEType type, const char* window, NPStream** stream); +#define NewNPN_NewStreamProc(FUNC) \ + ((NPN_NewStreamUPP) (FUNC)) +#define CallNPN_NewStreamProc(FUNC, npp, type, window, stream) \ + (*(FUNC))((npp), (type), (window), (stream)) /* NPN_Write */ typedef int32 (* NP_LOADDS NPN_WriteUPP)(NPP instance, NPStream* stream, int32 len, void* buffer); -#define NewNPN_WriteProc(FUNC) \ - ((NPN_WriteUPP) (FUNC)) -#define CallNPN_WriteProc(FUNC, npp, stream, len, buffer) \ - (*(FUNC))((npp), (stream), (len), (buffer)) +#define NewNPN_WriteProc(FUNC) \ + ((NPN_WriteUPP) (FUNC)) +#define CallNPN_WriteProc(FUNC, npp, stream, len, buffer) \ + (*(FUNC))((npp), (stream), (len), (buffer)) /* NPN_DestroyStream */ typedef NPError (* NP_LOADDS NPN_DestroyStreamUPP)(NPP instance, NPStream* stream, NPReason reason); -#define NewNPN_DestroyStreamProc(FUNC) \ - ((NPN_DestroyStreamUPP) (FUNC)) -#define CallNPN_DestroyStreamProc(FUNC, npp, stream, reason) \ - (*(FUNC))((npp), (stream), (reason)) +#define NewNPN_DestroyStreamProc(FUNC) \ + ((NPN_DestroyStreamUPP) (FUNC)) +#define CallNPN_DestroyStreamProc(FUNC, npp, stream, reason) \ + (*(FUNC))((npp), (stream), (reason)) /* NPN_Status */ typedef void (* NP_LOADDS NPN_StatusUPP)(NPP instance, const char* message); -#define NewNPN_StatusProc(FUNC) \ - ((NPN_StatusUPP) (FUNC)) -#define CallNPN_StatusProc(FUNC, npp, msg) \ - (*(FUNC))((npp), (msg)) +#define NewNPN_StatusProc(FUNC) \ + ((NPN_StatusUPP) (FUNC)) +#define CallNPN_StatusProc(FUNC, npp, msg) \ + (*(FUNC))((npp), (msg)) /* NPN_UserAgent */ -typedef const char* (* NP_LOADDS NPN_UserAgentUPP)(NPP instance); +typedef const char* (* NP_LOADDS NPN_UserAgentUPP)(NPP instance); #define NewNPN_UserAgentProc(FUNC) \ ((NPN_UserAgentUPP) (FUNC)) #define CallNPN_UserAgentProc(FUNC, ARG1) \ @@ -271,236 +271,236 @@ typedef const char* (* NP_LOADDS NPN_UserAgentUPP)(NPP instance); /* NPN_MemAlloc */ typedef void* (* NP_LOADDS NPN_MemAllocUPP)(uint32 size); -#define NewNPN_MemAllocProc(FUNC) \ - ((NPN_MemAllocUPP) (FUNC)) -#define CallNPN_MemAllocProc(FUNC, ARG1) \ - (*(FUNC))((ARG1)) +#define NewNPN_MemAllocProc(FUNC) \ + ((NPN_MemAllocUPP) (FUNC)) +#define CallNPN_MemAllocProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) /* NPN__MemFree */ typedef void (* NP_LOADDS NPN_MemFreeUPP)(void* ptr); -#define NewNPN_MemFreeProc(FUNC) \ - ((NPN_MemFreeUPP) (FUNC)) -#define CallNPN_MemFreeProc(FUNC, ARG1) \ - (*(FUNC))((ARG1)) +#define NewNPN_MemFreeProc(FUNC) \ + ((NPN_MemFreeUPP) (FUNC)) +#define CallNPN_MemFreeProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) /* NPN_MemFlush */ typedef uint32 (* NP_LOADDS NPN_MemFlushUPP)(uint32 size); -#define NewNPN_MemFlushProc(FUNC) \ - ((NPN_MemFlushUPP) (FUNC)) -#define CallNPN_MemFlushProc(FUNC, ARG1) \ - (*(FUNC))((ARG1)) +#define NewNPN_MemFlushProc(FUNC) \ + ((NPN_MemFlushUPP) (FUNC)) +#define CallNPN_MemFlushProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) /* NPN_ReloadPlugins */ typedef void (* NP_LOADDS NPN_ReloadPluginsUPP)(NPBool reloadPages); -#define NewNPN_ReloadPluginsProc(FUNC) \ - ((NPN_ReloadPluginsUPP) (FUNC)) -#define CallNPN_ReloadPluginsProc(FUNC, ARG1) \ - (*(FUNC))((ARG1)) +#define NewNPN_ReloadPluginsProc(FUNC) \ + ((NPN_ReloadPluginsUPP) (FUNC)) +#define CallNPN_ReloadPluginsProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) /* NPN_GetJavaEnv */ typedef JRIEnv* (* NP_LOADDS NPN_GetJavaEnvUPP)(void); -#define NewNPN_GetJavaEnvProc(FUNC) \ - ((NPN_GetJavaEnvUPP) (FUNC)) -#define CallNPN_GetJavaEnvProc(FUNC) \ - (*(FUNC))() +#define NewNPN_GetJavaEnvProc(FUNC) \ + ((NPN_GetJavaEnvUPP) (FUNC)) +#define CallNPN_GetJavaEnvProc(FUNC) \ + (*(FUNC))() /* NPN_GetJavaPeer */ typedef jref (* NP_LOADDS NPN_GetJavaPeerUPP)(NPP instance); -#define NewNPN_GetJavaPeerProc(FUNC) \ - ((NPN_GetJavaPeerUPP) (FUNC)) -#define CallNPN_GetJavaPeerProc(FUNC, ARG1) \ - (*(FUNC))((ARG1)) +#define NewNPN_GetJavaPeerProc(FUNC) \ + ((NPN_GetJavaPeerUPP) (FUNC)) +#define CallNPN_GetJavaPeerProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) /* NPN_InvalidateRect */ typedef void (* NP_LOADDS NPN_InvalidateRectUPP)(NPP instance, NPRect *rect); -#define NewNPN_InvalidateRectProc(FUNC) \ - ((NPN_InvalidateRectUPP) (FUNC)) -#define CallNPN_InvalidateRectProc(FUNC, ARG1, ARG2) \ - (*(FUNC))((ARG1), (ARG2)) +#define NewNPN_InvalidateRectProc(FUNC) \ + ((NPN_InvalidateRectUPP) (FUNC)) +#define CallNPN_InvalidateRectProc(FUNC, ARG1, ARG2) \ + (*(FUNC))((ARG1), (ARG2)) /* NPN_InvalidateRegion */ typedef void (* NP_LOADDS NPN_InvalidateRegionUPP)(NPP instance, NPRegion region); -#define NewNPN_InvalidateRegionProc(FUNC) \ - ((NPN_InvalidateRegionUPP) (FUNC)) -#define CallNPN_InvalidateRegionProc(FUNC, ARG1, ARG2) \ - (*(FUNC))((ARG1), (ARG2)) +#define NewNPN_InvalidateRegionProc(FUNC) \ + ((NPN_InvalidateRegionUPP) (FUNC)) +#define CallNPN_InvalidateRegionProc(FUNC, ARG1, ARG2) \ + (*(FUNC))((ARG1), (ARG2)) /* NPN_ForceRedraw */ typedef void (* NP_LOADDS NPN_ForceRedrawUPP)(NPP instance); -#define NewNPN_ForceRedrawProc(FUNC) \ - ((NPN_ForceRedrawUPP) (FUNC)) -#define CallNPN_ForceRedrawProc(FUNC, ARG1) \ - (*(FUNC))((ARG1)) +#define NewNPN_ForceRedrawProc(FUNC) \ + ((NPN_ForceRedrawUPP) (FUNC)) +#define CallNPN_ForceRedrawProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) /* NPN_GetStringIdentifier */ typedef NPIdentifier (* NP_LOADDS NPN_GetStringIdentifierUPP)(const NPUTF8* name); -#define NewNPN_GetStringIdentifierProc(FUNC) \ - ((NPN_GetStringIdentifierUPP) (FUNC)) -#define CallNPN_GetStringIdentifierProc(FUNC, ARG1) \ - (*(FUNC))((ARG1)) +#define NewNPN_GetStringIdentifierProc(FUNC) \ + ((NPN_GetStringIdentifierUPP) (FUNC)) +#define CallNPN_GetStringIdentifierProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) /* NPN_GetStringIdentifiers */ typedef void (* NP_LOADDS NPN_GetStringIdentifiersUPP)(const NPUTF8** names, int32_t nameCount, NPIdentifier* identifiers); -#define NewNPN_GetStringIdentifiersProc(FUNC) \ - ((NPN_GetStringIdentifiersUPP) (FUNC)) -#define CallNPN_GetStringIdentifiersProc(FUNC, ARG1, ARG2, ARG3) \ - (*(FUNC))((ARG1), (ARG2), (ARG3)) +#define NewNPN_GetStringIdentifiersProc(FUNC) \ + ((NPN_GetStringIdentifiersUPP) (FUNC)) +#define CallNPN_GetStringIdentifiersProc(FUNC, ARG1, ARG2, ARG3) \ + (*(FUNC))((ARG1), (ARG2), (ARG3)) /* NPN_GetIntIdentifier */ typedef NPIdentifier (* NP_LOADDS NPN_GetIntIdentifierUPP)(int32_t intid); -#define NewNPN_GetIntIdentifierProc(FUNC) \ - ((NPN_GetIntIdentifierUPP) (FUNC)) -#define CallNPN_GetIntIdentifierProc(FUNC, ARG1) \ - (*(FUNC))((ARG1)) +#define NewNPN_GetIntIdentifierProc(FUNC) \ + ((NPN_GetIntIdentifierUPP) (FUNC)) +#define CallNPN_GetIntIdentifierProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) /* NPN_IdentifierIsString */ typedef bool (* NP_LOADDS NPN_IdentifierIsStringUPP)(NPIdentifier identifier); -#define NewNPN_IdentifierIsStringProc(FUNC) \ - ((NPN_IdentifierIsStringUPP) (FUNC)) -#define CallNPN_IdentifierIsStringProc(FUNC, ARG1) \ - (*(FUNC))((ARG1)) +#define NewNPN_IdentifierIsStringProc(FUNC) \ + ((NPN_IdentifierIsStringUPP) (FUNC)) +#define CallNPN_IdentifierIsStringProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) /* NPN_UTF8FromIdentifier */ typedef NPUTF8* (* NP_LOADDS NPN_UTF8FromIdentifierUPP)(NPIdentifier identifier); -#define NewNPN_UTF8FromIdentifierProc(FUNC) \ - ((NPN_UTF8FromIdentifierUPP) (FUNC)) -#define CallNPN_UTF8FromIdentifierProc(FUNC, ARG1) \ - (*(FUNC))((ARG1)) +#define NewNPN_UTF8FromIdentifierProc(FUNC) \ + ((NPN_UTF8FromIdentifierUPP) (FUNC)) +#define CallNPN_UTF8FromIdentifierProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) /* NPN_IntFromIdentifier */ typedef int32_t (* NP_LOADDS NPN_IntFromIdentifierUPP)(NPIdentifier identifier); -#define NewNPN_IntFromIdentifierProc(FUNC) \ - ((NPN_IntFromIdentifierUPP) (FUNC)) -#define CallNPN_IntFromIdentifierProc(FUNC, ARG1) \ - (*(FUNC))((ARG1)) +#define NewNPN_IntFromIdentifierProc(FUNC) \ + ((NPN_IntFromIdentifierUPP) (FUNC)) +#define CallNPN_IntFromIdentifierProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) /* NPN_CreateObject */ typedef NPObject* (* NP_LOADDS NPN_CreateObjectUPP)(NPP npp, NPClass *aClass); -#define NewNPN_CreateObjectProc(FUNC) \ - ((NPN_CreateObjectUPP) (FUNC)) -#define CallNPN_CreateObjectProc(FUNC, ARG1, ARG2) \ - (*(FUNC))((ARG1), (ARG2)) +#define NewNPN_CreateObjectProc(FUNC) \ + ((NPN_CreateObjectUPP) (FUNC)) +#define CallNPN_CreateObjectProc(FUNC, ARG1, ARG2) \ + (*(FUNC))((ARG1), (ARG2)) /* NPN_RetainObject */ typedef NPObject* (* NP_LOADDS NPN_RetainObjectUPP)(NPObject *obj); -#define NewNPN_RetainObjectProc(FUNC) \ - ((NPN_RetainObjectUPP) (FUNC)) -#define CallNPN_RetainObjectProc(FUNC, ARG1) \ - (*(FUNC))((ARG1)) +#define NewNPN_RetainObjectProc(FUNC) \ + ((NPN_RetainObjectUPP) (FUNC)) +#define CallNPN_RetainObjectProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) /* NPN_ReleaseObject */ typedef void (* NP_LOADDS NPN_ReleaseObjectUPP)(NPObject *obj); -#define NewNPN_ReleaseObjectProc(FUNC) \ - ((NPN_ReleaseObjectUPP) (FUNC)) -#define CallNPN_ReleaseObjectProc(FUNC, ARG1) \ - (*(FUNC))((ARG1)) +#define NewNPN_ReleaseObjectProc(FUNC) \ + ((NPN_ReleaseObjectUPP) (FUNC)) +#define CallNPN_ReleaseObjectProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) /* NPN_Invoke */ typedef bool (* NP_LOADDS NPN_InvokeUPP)(NPP npp, NPObject* obj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result); -#define NewNPN_InvokeProc(FUNC) \ - ((NPN_InvokeUPP) (FUNC)) -#define CallNPN_InvokeProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) \ - (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6)) +#define NewNPN_InvokeProc(FUNC) \ + ((NPN_InvokeUPP) (FUNC)) +#define CallNPN_InvokeProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6)) /* NPN_InvokeDefault */ typedef bool (* NP_LOADDS NPN_InvokeDefaultUPP)(NPP npp, NPObject* obj, const NPVariant *args, uint32_t argCount, NPVariant *result); -#define NewNPN_InvokeDefaultProc(FUNC) \ - ((NPN_InvokeDefaultUPP) (FUNC)) -#define CallNPN_InvokeDefaultProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5) \ - (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5)) +#define NewNPN_InvokeDefaultProc(FUNC) \ + ((NPN_InvokeDefaultUPP) (FUNC)) +#define CallNPN_InvokeDefaultProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5)) /* NPN_Evaluate */ typedef bool (* NP_LOADDS NPN_EvaluateUPP)(NPP npp, NPObject *obj, NPString *script, NPVariant *result); -#define NewNPN_EvaluateProc(FUNC) \ - ((NPN_EvaluateUPP) (FUNC)) -#define CallNPN_EvaluateProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ - (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4)) +#define NewNPN_EvaluateProc(FUNC) \ + ((NPN_EvaluateUPP) (FUNC)) +#define CallNPN_EvaluateProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4)) /* NPN_GetProperty */ typedef bool (* NP_LOADDS NPN_GetPropertyUPP)(NPP npp, NPObject *obj, NPIdentifier propertyName, NPVariant *result); -#define NewNPN_GetPropertyProc(FUNC) \ - ((NPN_GetPropertyUPP) (FUNC)) -#define CallNPN_GetPropertyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ - (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4)) +#define NewNPN_GetPropertyProc(FUNC) \ + ((NPN_GetPropertyUPP) (FUNC)) +#define CallNPN_GetPropertyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4)) /* NPN_SetProperty */ typedef bool (* NP_LOADDS NPN_SetPropertyUPP)(NPP npp, NPObject *obj, NPIdentifier propertyName, const NPVariant *value); -#define NewNPN_SetPropertyProc(FUNC) \ - ((NPN_SetPropertyUPP) (FUNC)) -#define CallNPN_SetPropertyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ - (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4)) +#define NewNPN_SetPropertyProc(FUNC) \ + ((NPN_SetPropertyUPP) (FUNC)) +#define CallNPN_SetPropertyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4)) /* NPN_RemoveProperty */ typedef bool (* NP_LOADDS NPN_RemovePropertyUPP)(NPP npp, NPObject *obj, NPIdentifier propertyName); -#define NewNPN_RemovePropertyProc(FUNC) \ - ((NPN_RemovePropertyUPP) (FUNC)) -#define CallNPN_RemovePropertyProc(FUNC, ARG1, ARG2, ARG3) \ - (*(FUNC))((ARG1), (ARG2), (ARG3)) +#define NewNPN_RemovePropertyProc(FUNC) \ + ((NPN_RemovePropertyUPP) (FUNC)) +#define CallNPN_RemovePropertyProc(FUNC, ARG1, ARG2, ARG3) \ + (*(FUNC))((ARG1), (ARG2), (ARG3)) /* NPN_HasProperty */ typedef bool (* NP_LOADDS NPN_HasPropertyUPP)(NPP npp, NPObject *obj, NPIdentifier propertyName); -#define NewNPN_HasPropertyProc(FUNC) \ - ((NPN_HasPropertyUPP) (FUNC)) -#define CallNPN_HasPropertyProc(FUNC, ARG1, ARG2, ARG3) \ - (*(FUNC))((ARG1), (ARG2), (ARG3)) +#define NewNPN_HasPropertyProc(FUNC) \ + ((NPN_HasPropertyUPP) (FUNC)) +#define CallNPN_HasPropertyProc(FUNC, ARG1, ARG2, ARG3) \ + (*(FUNC))((ARG1), (ARG2), (ARG3)) /* NPN_HasMethod */ typedef bool (* NP_LOADDS NPN_HasMethodUPP)(NPP npp, NPObject *obj, NPIdentifier propertyName); -#define NewNPN_HasMethodProc(FUNC) \ - ((NPN_HasMethodUPP) (FUNC)) -#define CallNPN_HasMethodProc(FUNC, ARG1, ARG2, ARG3) \ - (*(FUNC))((ARG1), (ARG2), (ARG3)) +#define NewNPN_HasMethodProc(FUNC) \ + ((NPN_HasMethodUPP) (FUNC)) +#define CallNPN_HasMethodProc(FUNC, ARG1, ARG2, ARG3) \ + (*(FUNC))((ARG1), (ARG2), (ARG3)) /* NPN_ReleaseVariantValue */ typedef void (* NP_LOADDS NPN_ReleaseVariantValueUPP)(NPVariant *variant); -#define NewNPN_ReleaseVariantValueProc(FUNC) \ - ((NPN_ReleaseVariantValueUPP) (FUNC)) -#define CallNPN_ReleaseVariantValueProc(FUNC, ARG1) \ - (*(FUNC))((ARG1)) +#define NewNPN_ReleaseVariantValueProc(FUNC) \ + ((NPN_ReleaseVariantValueUPP) (FUNC)) +#define CallNPN_ReleaseVariantValueProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) /* NPN_SetException */ typedef void (* NP_LOADDS NPN_SetExceptionUPP)(NPObject *obj, const NPUTF8 *message); -#define NewNPN_SetExceptionProc(FUNC) \ - ((NPN_SetExceptionUPP) (FUNC)) -#define CallNPN_SetExceptionProc(FUNC, ARG1, ARG2) \ - (*(FUNC))((ARG1), (ARG2)) +#define NewNPN_SetExceptionProc(FUNC) \ + ((NPN_SetExceptionUPP) (FUNC)) +#define CallNPN_SetExceptionProc(FUNC, ARG1, ARG2) \ + (*(FUNC))((ARG1), (ARG2)) /* NPN_PushPopupsEnabledStateUPP */ typedef bool (* NP_LOADDS NPN_PushPopupsEnabledStateUPP)(NPP npp, NPBool enabled); -#define NewNPN_PushPopupsEnabledStateProc(FUNC) \ - ((NPN_PushPopupsEnabledStateUPP) (FUNC)) -#define CallNPN_PushPopupsEnabledStateProc(FUNC, ARG1, ARG2) \ - (*(FUNC))((ARG1), (ARG2)) +#define NewNPN_PushPopupsEnabledStateProc(FUNC) \ + ((NPN_PushPopupsEnabledStateUPP) (FUNC)) +#define CallNPN_PushPopupsEnabledStateProc(FUNC, ARG1, ARG2) \ + (*(FUNC))((ARG1), (ARG2)) /* NPN_PopPopupsEnabledState */ typedef bool (* NP_LOADDS NPN_PopPopupsEnabledStateUPP)(NPP npp); -#define NewNPN_PopPopupsEnabledStateProc(FUNC) \ - ((NPN_PopPopupsEnabledStateUPP) (FUNC)) -#define CallNPN_PopPopupsEnabledStateProc(FUNC, ARG1) \ - (*(FUNC))((ARG1)) +#define NewNPN_PopPopupsEnabledStateProc(FUNC) \ + ((NPN_PopPopupsEnabledStateUPP) (FUNC)) +#define CallNPN_PopPopupsEnabledStateProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) /* NPN_Enumerate */ typedef bool (* NP_LOADDS NPN_EnumerateUPP)(NPP npp, NPObject *obj, NPIdentifier **identifier, uint32_t *count); -#define NewNPN_EnumerateProc(FUNC) \ - ((NPN_EnumerateUPP) (FUNC)) -#define CallNPN_EnumerateProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ - (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4)) +#define NewNPN_EnumerateProc(FUNC) \ + ((NPN_EnumerateUPP) (FUNC)) +#define CallNPN_EnumerateProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4)) /* NPN_PluginThreadAsyncCall */ typedef void (* NP_LOADDS NPN_PluginThreadAsyncCallUPP)(NPP instance, void (*func)(void *), void *userData); #define NewNPN_PluginThreadAsyncCallProc(FUNC) \ - ((NPN_PluginThreadAsyncCallUPP) (FUNC)) + ((NPN_PluginThreadAsyncCallUPP) (FUNC)) #define CallNPN_PluginThreadAsyncCallProc(FUNC, ARG1, ARG2, ARG3) \ - (*(FUNC))((ARG1), (ARG2), (ARG3)) + (*(FUNC))((ARG1), (ARG2), (ARG3)) /* NPN_Construct */ typedef bool (* NP_LOADDS NPN_ConstructUPP)(NPP npp, NPObject* obj, const NPVariant *args, uint32_t argCount, NPVariant *result); -#define NewNPN_ConstructProc(FUNC) \ - ((NPN_ConstructUPP) (FUNC)) +#define NewNPN_ConstructProc(FUNC) \ + ((NPN_ConstructUPP) (FUNC)) #define CallNPN_ConstructProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5) \ - (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5)) + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5)) @@ -590,17 +590,17 @@ typedef struct _NPNetscapeFuncs { * and NPPShutdownUPP for Netscape's use. */ typedef NPError (* NP_LOADDS NPP_MainEntryUPP)(NPNetscapeFuncs*, NPPluginFuncs*, NPP_ShutdownUPP*); -#define NewNPP_MainEntryProc(FUNC) \ - ((NPP_MainEntryUPP) (FUNC)) -#define CallNPP_MainEntryProc(FUNC, netscapeFunc, pluginFunc, shutdownUPP) \ - (*(FUNC))((netscapeFunc), (pluginFunc), (shutdownUPP)) +#define NewNPP_MainEntryProc(FUNC) \ + ((NPP_MainEntryUPP) (FUNC)) +#define CallNPP_MainEntryProc(FUNC, netscapeFunc, pluginFunc, shutdownUPP) \ + (*(FUNC))((netscapeFunc), (pluginFunc), (shutdownUPP)) /* * Mac OS X version(s) of NP_GetMIMEDescription(const char *) * These can be called to retreive MIME information from the plugin dynamically * * Note: For compatibility with Quicktime, BPSupportedMIMEtypes is another way - * to get mime info from the plugin only on OSX and may not be supported + * to get mime info from the plugin only on OSX and may not be supported * in furture version -- use NP_GetMIMEDescription instead */ @@ -620,17 +620,17 @@ OSErr BP_GetSupportedMIMETypes(BPSupportedMIMETypes *mimeInfo, UInt32 flags); /* NP_GetMIMEDescription */ #define NP_GETMIMEDESCRIPTION_NAME "NP_GetMIMEDescription" typedef const char* (* NP_LOADDS NP_GetMIMEDescriptionUPP)(); -#define NewNP_GetMIMEDescEntryProc(FUNC) \ - ((NP_GetMIMEDescriptionUPP) (FUNC)) -#define CallNP_GetMIMEDescEntryProc(FUNC) \ - (*(FUNC))() +#define NewNP_GetMIMEDescEntryProc(FUNC) \ + ((NP_GetMIMEDescriptionUPP) (FUNC)) +#define CallNP_GetMIMEDescEntryProc(FUNC) \ + (*(FUNC))() /* BP_GetSupportedMIMETypes */ typedef OSErr (* NP_LOADDS BP_GetSupportedMIMETypesUPP)(BPSupportedMIMETypes*, UInt32); -#define NewBP_GetSupportedMIMETypesEntryProc(FUNC) \ - ((BP_GetSupportedMIMETypesUPP) (FUNC)) -#define CallBP_GetMIMEDescEntryProc(FUNC, mimeInfo, flags) \ - (*(FUNC))((mimeInfo), (flags)) +#define NewBP_GetSupportedMIMETypesEntryProc(FUNC) \ + ((BP_GetSupportedMIMETypesUPP) (FUNC)) +#define CallBP_GetMIMEDescEntryProc(FUNC, mimeInfo, flags) \ + (*(FUNC))((mimeInfo), (flags)) #endif /* XP_MACOSX */ @@ -685,7 +685,7 @@ NPError OSCALL NP_Initialize(NPNetscapeFuncs* pFuncs); NPError OSCALL NP_Shutdown(); -char* NP_GetMIMEDescription(); +char* !NP_GetMIMEDescription(); #ifdef __cplusplus } diff --git a/plugin/virt-viewer-plugin.c b/plugin/virt-viewer-plugin.c index 00902e1..b27ebf1 100644 --- a/plugin/virt-viewer-plugin.c +++ b/plugin/virt-viewer-plugin.c @@ -83,7 +83,7 @@ VirtViewerXSetWindow (NPP instance, NPWindow *window) /* Make the VNC widget. */ if (This->uri && This->name) { debug ("calling viewer_start uri=%s name=%s direct=%d waitvm=%d reconnect=%d container=%p", - This->uri, This->name, This->direct, This->waitvm, This->reconnect, This->container); + This->uri, This->name, This->direct, This->waitvm, This->reconnect, This->container); r = viewer_start (This->uri, This->name, This->direct, This->waitvm, This->reconnect, 1, This->debug, This->container); if (r != 0) fprintf (stderr, "viewer_start returned %d != 0\n", r); diff --git a/src/remote-viewer-main.c b/src/remote-viewer-main.c index fc491e9..9fecdb1 100644 --- a/src/remote-viewer-main.c +++ b/src/remote-viewer-main.c @@ -39,131 +39,130 @@ static void remote_viewer_version(void) { - g_print(_("remote-viewer version %s\n"), VERSION); - exit(0); + g_print(_("remote-viewer version %s\n"), VERSION); + exit(0); } int main(int argc, char **argv) { - GOptionContext *context; - GError *error = NULL; - int ret = 1; - int zoom = 100; - gchar **args = NULL; - gboolean verbose = FALSE; - gboolean debug = FALSE; - gboolean direct = FALSE; - gboolean fullscreen = FALSE; - RemoteViewer *viewer = NULL; + GOptionContext *context; + GError *error = NULL; + int ret = 1; + int zoom = 100; + gchar **args = NULL; + gboolean verbose = FALSE; + gboolean debug = FALSE; + gboolean direct = FALSE; + gboolean fullscreen = FALSE; + RemoteViewer *viewer = NULL; #if HAVE_SPICE_GTK - gboolean controller = FALSE; + gboolean controller = FALSE; #endif - VirtViewerApp *app; - const char *help_msg = N_("Run '" PACKAGE " --help' to see a full list of available command line options"); - const GOptionEntry options [] = { - { "version", 'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, - remote_viewer_version, N_("Display version information"), NULL }, - { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, - N_("Display verbose information"), NULL }, - { "direct", 'd', 0, G_OPTION_ARG_NONE, &direct, - N_("Direct connection with no automatic tunnels"), NULL }, - { "zoom", 'z', 0, G_OPTION_ARG_INT, &zoom, - N_("Zoom level of window, in percentage"), "ZOOM" }, - { "debug", '\0', 0, G_OPTION_ARG_NONE, &debug, - N_("Display debugging information"), NULL }, - { "full-screen", 'f', 0, G_OPTION_ARG_NONE, &fullscreen, - N_("Open in full screen mode"), NULL }, + VirtViewerApp *app; + const char *help_msg = N_("Run '" PACKAGE " --help' to see a full list of available command line options"); + const GOptionEntry options [] = { + { "version", 'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, + remote_viewer_version, N_("Display version information"), NULL }, + { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, + N_("Display verbose information"), NULL }, + { "direct", 'd', 0, G_OPTION_ARG_NONE, &direct, + N_("Direct connection with no automatic tunnels"), NULL }, + { "zoom", 'z', 0, G_OPTION_ARG_INT, &zoom, + N_("Zoom level of window, in percentage"), "ZOOM" }, + { "debug", '\0', 0, G_OPTION_ARG_NONE, &debug, + N_("Display debugging information"), NULL }, + { "full-screen", 'f', 0, G_OPTION_ARG_NONE, &fullscreen, + N_("Open in full screen mode"), NULL }, #if HAVE_SPICE_GTK - { "spice-controller", '\0', 0, G_OPTION_ARG_NONE, &controller, - N_("Open connection using Spice controller communication"), NULL }, + { "spice-controller", '\0', 0, G_OPTION_ARG_NONE, &controller, + N_("Open connection using Spice controller communication"), NULL }, #endif - { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &args, - NULL, "URI" }, - { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } - }; - - setlocale(LC_ALL, ""); - bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR); - bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); - textdomain(GETTEXT_PACKAGE); - - /* Setup command line options */ - context = g_option_context_new (_("- Remote viewer client")); - g_option_context_add_main_entries (context, options, NULL); - g_option_context_add_group (context, gtk_get_option_group (TRUE)); + { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &args, + NULL, "URI" }, + { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } + }; + + setlocale(LC_ALL, ""); + bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR); + bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); + textdomain(GETTEXT_PACKAGE); + + /* Setup command line options */ + context = g_option_context_new (_("- Remote viewer client")); + g_option_context_add_main_entries (context, options, NULL); + g_option_context_add_group (context, gtk_get_option_group (TRUE)); #ifdef HAVE_GTK_VNC - g_option_context_add_group (context, vnc_display_get_option_group ()); + g_option_context_add_group (context, vnc_display_get_option_group ()); #endif #ifdef HAVE_SPICE_GTK - g_option_context_add_group (context, spice_get_option_group ()); + g_option_context_add_group (context, spice_get_option_group ()); #endif - g_option_context_parse (context, &argc, &argv, &error); - if (error) { - g_printerr("%s\n%s\n", - error->message, - gettext(help_msg)); - g_error_free(error); - goto cleanup; - } - - g_option_context_free(context); - - if ((!args || (g_strv_length(args) != 1)) + g_option_context_parse (context, &argc, &argv, &error); + if (error) { + g_printerr("%s\n%s\n", + error->message, + gettext(help_msg)); + g_error_free(error); + goto cleanup; + } + + g_option_context_free(context); + + if ((!args || (g_strv_length(args) != 1)) #if HAVE_SPICE_GTK - && !controller + && !controller #endif - ) { - g_printerr(_("\nUsage: %s [OPTIONS] URI\n\n%s\n\n"), argv[0], help_msg); - goto cleanup; - } + ) { + g_printerr(_("\nUsage: %s [OPTIONS] URI\n\n%s\n\n"), argv[0], help_msg); + goto cleanup; + } - if (zoom < 10 || zoom > 200) { - g_printerr(_("Zoom level must be within 10-200\n")); - goto cleanup; - } + if (zoom < 10 || zoom > 200) { + g_printerr(_("Zoom level must be within 10-200\n")); + goto cleanup; + } - virt_viewer_app_set_debug(debug); + virt_viewer_app_set_debug(debug); #if HAVE_SPICE_GTK - if (controller) { - viewer = remote_viewer_new_with_controller(verbose); - g_object_set(viewer, "guest-name", "defined by Spice controller", NULL); - } else { + if (controller) { + viewer = remote_viewer_new_with_controller(verbose); + g_object_set(viewer, "guest-name", "defined by Spice controller", NULL); + } else { #endif - viewer = remote_viewer_new(args[0], verbose); - g_object_set(viewer, "guest-name", args[0], NULL); + viewer = remote_viewer_new(args[0], verbose); + g_object_set(viewer, "guest-name", args[0], NULL); #if HAVE_SPICE_GTK - } + } #endif - if (viewer == NULL) - goto cleanup; + if (viewer == NULL) + goto cleanup; - app = VIRT_VIEWER_APP(viewer); - g_object_set(app, "fullscreen", fullscreen, NULL); - virt_viewer_window_set_zoom_level(virt_viewer_app_get_main_window(app), zoom); - virt_viewer_app_set_direct(app, direct); + app = VIRT_VIEWER_APP(viewer); + g_object_set(app, "fullscreen", fullscreen, NULL); + virt_viewer_window_set_zoom_level(virt_viewer_app_get_main_window(app), zoom); + virt_viewer_app_set_direct(app, direct); - if (!virt_viewer_app_start(app)) - goto cleanup; + if (!virt_viewer_app_start(app)) + goto cleanup; - gtk_main(); + gtk_main(); - ret = 0; + ret = 0; -cleanup: - if (viewer) - g_object_unref(viewer); - g_strfreev(args); + cleanup: + if (viewer) + g_object_unref(viewer); + g_strfreev(args); - return ret; + return ret; } /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 - * indent-tabs-mode: t + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/remote-viewer.c b/src/remote-viewer.c index 6af8c78..83a0176 100644 --- a/src/remote-viewer.c +++ b/src/remote-viewer.c @@ -39,19 +39,19 @@ struct _RemoteViewerPrivate { #ifdef HAVE_SPICE_GTK - SpiceCtrlController *controller; + SpiceCtrlController *controller; #endif - GtkWidget *controller_menu; + GtkWidget *controller_menu; }; G_DEFINE_TYPE (RemoteViewer, remote_viewer, VIRT_VIEWER_TYPE_APP) -#define GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), REMOTE_VIEWER_TYPE, RemoteViewerPrivate)) +#define GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), REMOTE_VIEWER_TYPE, RemoteViewerPrivate)) #if HAVE_SPICE_GTK enum { - PROP_0, - PROP_CONTROLLER, + PROP_0, + PROP_CONTROLLER, }; #endif @@ -64,49 +64,49 @@ static void remote_viewer_window_added(VirtViewerApp *self, VirtViewerWindow *wi #if HAVE_SPICE_GTK static void remote_viewer_get_property (GObject *object, guint property_id, - GValue *value, GParamSpec *pspec) + GValue *value, GParamSpec *pspec) { - RemoteViewer *self = REMOTE_VIEWER(object); - RemoteViewerPrivate *priv = self->priv; - - switch (property_id) { - case PROP_CONTROLLER: - g_value_set_object(value, priv->controller); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } + RemoteViewer *self = REMOTE_VIEWER(object); + RemoteViewerPrivate *priv = self->priv; + + switch (property_id) { + case PROP_CONTROLLER: + g_value_set_object(value, priv->controller); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } } static void remote_viewer_set_property (GObject *object, guint property_id, - const GValue *value, GParamSpec *pspec) + const GValue *value, GParamSpec *pspec) { - RemoteViewer *self = REMOTE_VIEWER(object); - RemoteViewerPrivate *priv = self->priv; - - switch (property_id) { - case PROP_CONTROLLER: - g_return_if_fail(priv->controller == NULL); - priv->controller = g_value_dup_object(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } + RemoteViewer *self = REMOTE_VIEWER(object); + RemoteViewerPrivate *priv = self->priv; + + switch (property_id) { + case PROP_CONTROLLER: + g_return_if_fail(priv->controller == NULL); + priv->controller = g_value_dup_object(value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } } static void remote_viewer_dispose (GObject *object) { - RemoteViewer *self = REMOTE_VIEWER(object); - RemoteViewerPrivate *priv = self->priv; + RemoteViewer *self = REMOTE_VIEWER(object); + RemoteViewerPrivate *priv = self->priv; - if (priv->controller) { - g_object_unref(priv->controller); - priv->controller = NULL; - } + if (priv->controller) { + g_object_unref(priv->controller); + priv->controller = NULL; + } - G_OBJECT_CLASS(remote_viewer_parent_class)->dispose (object); + G_OBJECT_CLASS(remote_viewer_parent_class)->dispose (object); } #endif @@ -115,222 +115,222 @@ static void remote_viewer_class_init (RemoteViewerClass *klass) { #if HAVE_SPICE_GTK - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); #endif - VirtViewerAppClass *app_class = VIRT_VIEWER_APP_CLASS (klass); + VirtViewerAppClass *app_class = VIRT_VIEWER_APP_CLASS (klass); - g_type_class_add_private (klass, sizeof (RemoteViewerPrivate)); + g_type_class_add_private (klass, sizeof (RemoteViewerPrivate)); #if HAVE_SPICE_GTK - object_class->get_property = remote_viewer_get_property; - object_class->set_property = remote_viewer_set_property; - object_class->dispose = remote_viewer_dispose; + object_class->get_property = remote_viewer_get_property; + object_class->set_property = remote_viewer_set_property; + object_class->dispose = remote_viewer_dispose; #endif - app_class->start = remote_viewer_start; + app_class->start = remote_viewer_start; #if HAVE_SPICE_GTK - app_class->activate = remote_viewer_activate; + app_class->activate = remote_viewer_activate; #endif - app_class->window_added = remote_viewer_window_added; + app_class->window_added = remote_viewer_window_added; #if HAVE_SPICE_GTK - g_object_class_install_property(object_class, - PROP_CONTROLLER, - g_param_spec_object("controller", - "Controller", - "Spice controller", - SPICE_CTRL_TYPE_CONTROLLER, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + g_object_class_install_property(object_class, + PROP_CONTROLLER, + g_param_spec_object("controller", + "Controller", + "Spice controller", + SPICE_CTRL_TYPE_CONTROLLER, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); #endif } static void remote_viewer_init(RemoteViewer *self) { - self->priv = GET_PRIVATE(self); + self->priv = GET_PRIVATE(self); } RemoteViewer * remote_viewer_new(const gchar *uri, gboolean verbose) { - return g_object_new(REMOTE_VIEWER_TYPE, - "guri", uri, - "verbose", verbose, - NULL); + return g_object_new(REMOTE_VIEWER_TYPE, + "guri", uri, + "verbose", verbose, + NULL); } #if HAVE_SPICE_GTK RemoteViewer * remote_viewer_new_with_controller(gboolean verbose) { - RemoteViewer *self; - SpiceCtrlController *ctrl = spice_ctrl_controller_new(); + RemoteViewer *self; + SpiceCtrlController *ctrl = spice_ctrl_controller_new(); - self = g_object_new(REMOTE_VIEWER_TYPE, - "controller", ctrl, - "verbose", verbose, - NULL); - g_object_unref(ctrl); + self = g_object_new(REMOTE_VIEWER_TYPE, + "controller", ctrl, + "verbose", verbose, + NULL); + g_object_unref(ctrl); - return self; + return self; } static void spice_ctrl_do_connect(SpiceCtrlController *ctrl G_GNUC_UNUSED, - VirtViewerApp *self) + VirtViewerApp *self) { - if (virt_viewer_app_initial_connect(self) < 0) { - virt_viewer_app_simple_message_dialog(self, _("Failed to initiate connection")); - } + if (virt_viewer_app_initial_connect(self) < 0) { + virt_viewer_app_simple_message_dialog(self, _("Failed to initiate connection")); + } } static void spice_ctrl_show(SpiceCtrlController *ctrl G_GNUC_UNUSED, RemoteViewer *self) { - virt_viewer_app_show_display(VIRT_VIEWER_APP(self)); + virt_viewer_app_show_display(VIRT_VIEWER_APP(self)); } static void spice_ctrl_hide(SpiceCtrlController *ctrl G_GNUC_UNUSED, RemoteViewer *self) { - virt_viewer_app_show_status(VIRT_VIEWER_APP(self), _("Display disabled by controller")); + virt_viewer_app_show_status(VIRT_VIEWER_APP(self), _("Display disabled by controller")); } static void spice_menuitem_activate_cb(GtkMenuItem *mi, RemoteViewer *self) { - SpiceCtrlMenuItem *menuitem = g_object_get_data(G_OBJECT(mi), "spice-menuitem"); + SpiceCtrlMenuItem *menuitem = g_object_get_data(G_OBJECT(mi), "spice-menuitem"); - g_return_if_fail(menuitem != NULL); - if (gtk_menu_item_get_submenu(mi)) - return; + g_return_if_fail(menuitem != NULL); + if (gtk_menu_item_get_submenu(mi)) + return; - spice_ctrl_controller_menu_item_click_msg(self->priv->controller, menuitem->id); + spice_ctrl_controller_menu_item_click_msg(self->priv->controller, menuitem->id); } static GtkWidget * ctrlmenu_to_gtkmenu (RemoteViewer *self, SpiceCtrlMenu *ctrlmenu) { - GList *l; - GtkWidget *menu = gtk_menu_new(); - guint n = 0; - - for (l = ctrlmenu->items; l != NULL; l = l->next) { - SpiceCtrlMenuItem *menuitem = l->data; - GtkWidget *item; - char *s; - if (menuitem->text == NULL) { - g_warn_if_reached(); - continue; - } - - for (s = menuitem->text; *s; s++) - if (*s == '&') - *s = '_'; - - if (g_str_equal(menuitem->text, "-")){ - item = gtk_separator_menu_item_new(); - } else { - item = gtk_menu_item_new_with_mnemonic(menuitem->text); - } - - g_object_set_data_full(G_OBJECT(item), "spice-menuitem", - g_object_ref(menuitem), g_object_unref); - g_signal_connect(item, "activate", G_CALLBACK(spice_menuitem_activate_cb), self); - gtk_menu_attach(GTK_MENU (menu), item, 0, 1, n, n + 1); - n += 1; - - if (menuitem->submenu) { - gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), - ctrlmenu_to_gtkmenu(self, menuitem->submenu)); - } - } - - if (n == 0) { - g_object_ref_sink(menu); - g_object_unref(menu); - menu = NULL; - } - - gtk_widget_show_all(menu); - return menu; + GList *l; + GtkWidget *menu = gtk_menu_new(); + guint n = 0; + + for (l = ctrlmenu->items; l != NULL; l = l->next) { + SpiceCtrlMenuItem *menuitem = l->data; + GtkWidget *item; + char *s; + if (menuitem->text == NULL) { + g_warn_if_reached(); + continue; + } + + for (s = menuitem->text; *s; s++) + if (*s == '&') + *s = '_'; + + if (g_str_equal(menuitem->text, "-")){ + item = gtk_separator_menu_item_new(); + } else { + item = gtk_menu_item_new_with_mnemonic(menuitem->text); + } + + g_object_set_data_full(G_OBJECT(item), "spice-menuitem", + g_object_ref(menuitem), g_object_unref); + g_signal_connect(item, "activate", G_CALLBACK(spice_menuitem_activate_cb), self); + gtk_menu_attach(GTK_MENU (menu), item, 0, 1, n, n + 1); + n += 1; + + if (menuitem->submenu) { + gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), + ctrlmenu_to_gtkmenu(self, menuitem->submenu)); + } + } + + if (n == 0) { + g_object_ref_sink(menu); + g_object_unref(menu); + menu = NULL; + } + + gtk_widget_show_all(menu); + return menu; } static void spice_menu_set_visible(gpointer key G_GNUC_UNUSED, - gpointer value, - gpointer user_data) + gpointer value, + gpointer user_data) { - gboolean visible = GPOINTER_TO_INT(user_data); - GtkWidget *menu = g_object_get_data(value, "spice-menu"); + gboolean visible = GPOINTER_TO_INT(user_data); + GtkWidget *menu = g_object_get_data(value, "spice-menu"); - gtk_widget_set_visible(menu, visible); + gtk_widget_set_visible(menu, visible); } static void remote_viewer_window_spice_menu_set_visible(RemoteViewer *self, - gboolean visible) + gboolean visible) { - GHashTable *windows = virt_viewer_app_get_windows(VIRT_VIEWER_APP(self)); + GHashTable *windows = virt_viewer_app_get_windows(VIRT_VIEWER_APP(self)); - g_hash_table_foreach(windows, spice_menu_set_visible, GINT_TO_POINTER(visible)); + g_hash_table_foreach(windows, spice_menu_set_visible, GINT_TO_POINTER(visible)); } static void spice_menu_update(gpointer key G_GNUC_UNUSED, - gpointer value, - gpointer user_data) + gpointer value, + gpointer user_data) { - RemoteViewer *self = REMOTE_VIEWER(user_data); - GtkWidget *menuitem = g_object_get_data(value, "spice-menu"); - SpiceCtrlMenu *menu; + RemoteViewer *self = REMOTE_VIEWER(user_data); + GtkWidget *menuitem = g_object_get_data(value, "spice-menu"); + SpiceCtrlMenu *menu; - g_object_get(self->priv->controller, "menu", &menu, NULL); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), ctrlmenu_to_gtkmenu(self, menu)); - g_object_unref(menu); + g_object_get(self->priv->controller, "menu", &menu, NULL); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), ctrlmenu_to_gtkmenu(self, menu)); + g_object_unref(menu); } static void spice_ctrl_menu_updated(RemoteViewer *self, - SpiceCtrlMenu *menu) + SpiceCtrlMenu *menu) { - GHashTable *windows = virt_viewer_app_get_windows(VIRT_VIEWER_APP(self)); - RemoteViewerPrivate *priv = self->priv; - gboolean visible; + GHashTable *windows = virt_viewer_app_get_windows(VIRT_VIEWER_APP(self)); + RemoteViewerPrivate *priv = self->priv; + gboolean visible; - DEBUG_LOG("Spice controller menu updated"); + DEBUG_LOG("Spice controller menu updated"); - if (priv->controller_menu != NULL) { - g_object_unref (priv->controller_menu); - priv->controller_menu = NULL; - } + if (priv->controller_menu != NULL) { + g_object_unref (priv->controller_menu); + priv->controller_menu = NULL; + } - if (menu && g_list_length(menu->items) > 0) { - priv->controller_menu = ctrlmenu_to_gtkmenu(self, menu); - g_hash_table_foreach(windows, spice_menu_update, self); - } + if (menu && g_list_length(menu->items) > 0) { + priv->controller_menu = ctrlmenu_to_gtkmenu(self, menu); + g_hash_table_foreach(windows, spice_menu_update, self); + } - visible = priv->controller_menu != NULL; + visible = priv->controller_menu != NULL; - remote_viewer_window_spice_menu_set_visible(self, visible); + remote_viewer_window_spice_menu_set_visible(self, visible); } static SpiceSession * remote_viewer_get_spice_session(RemoteViewer *self) { - VirtViewerSession *vsession = NULL; - SpiceSession *session = NULL; + VirtViewerSession *vsession = NULL; + SpiceSession *session = NULL; - g_object_get(self, "session", &vsession, NULL); - g_return_val_if_fail(vsession != NULL, NULL); + g_object_get(self, "session", &vsession, NULL); + g_return_val_if_fail(vsession != NULL, NULL); - g_object_get(vsession, "spice-session", &session, NULL); + g_object_get(vsession, "spice-session", &session, NULL); - g_object_unref(vsession); + g_object_unref(vsession); - return session; + return session; } #ifndef G_VALUE_INIT /* see bug https://bugzilla.gnome.org/show_bug.cgi?id=654793 */ @@ -339,166 +339,165 @@ remote_viewer_get_spice_session(RemoteViewer *self) static void spice_ctrl_notified(SpiceCtrlController *ctrl, - GParamSpec *pspec, - RemoteViewer *self) + GParamSpec *pspec, + RemoteViewer *self) { - SpiceSession *session = remote_viewer_get_spice_session(self); - GValue value = G_VALUE_INIT; - VirtViewerApp *app = VIRT_VIEWER_APP(self); - - g_return_if_fail(session != NULL); - - g_value_init(&value, pspec->value_type); - g_object_get_property(G_OBJECT(ctrl), pspec->name, &value); - - if (g_str_equal(pspec->name, "host") || - g_str_equal(pspec->name, "port") || - g_str_equal(pspec->name, "password") || - g_str_equal(pspec->name, "ca-file")) { - g_object_set_property(G_OBJECT(session), pspec->name, &value); - } else if (g_str_equal(pspec->name, "sport")) { - g_object_set_property(G_OBJECT(session), "tls-port", &value); - } else if (g_str_equal(pspec->name, "tls-ciphers")) { - g_object_set_property(G_OBJECT(session), "ciphers", &value); - } else if (g_str_equal(pspec->name, "host-subject")) { - g_object_set_property(G_OBJECT(session), "cert-subject", &value); - } else if (g_str_equal(pspec->name, "title")) { - g_object_set_property(G_OBJECT(app), "title", &value); - } else if (g_str_equal(pspec->name, "display-flags")) { - guint flags = g_value_get_uint(&value); - gboolean fullscreen = flags & CONTROLLER_SET_FULL_SCREEN; - gboolean auto_res = flags & CONTROLLER_AUTO_DISPLAY_RES; - g_object_set(G_OBJECT(self), "fullscreen", fullscreen, NULL); - g_debug("unimplemented resize-guest %d", auto_res); - /* g_object_set(G_OBJECT(self), "resize-guest", auto_res, NULL); */ - } else if (g_str_equal(pspec->name, "menu")) { - spice_ctrl_menu_updated(self, g_value_get_object(&value)); - } else { - gchar *content = g_strdup_value_contents(&value); - - g_debug("unimplemented property: %s=%s", pspec->name, content); - g_free(content); - } - - g_object_unref(session); - g_value_unset(&value); + SpiceSession *session = remote_viewer_get_spice_session(self); + GValue value = G_VALUE_INIT; + VirtViewerApp *app = VIRT_VIEWER_APP(self); + + g_return_if_fail(session != NULL); + + g_value_init(&value, pspec->value_type); + g_object_get_property(G_OBJECT(ctrl), pspec->name, &value); + + if (g_str_equal(pspec->name, "host") || + g_str_equal(pspec->name, "port") || + g_str_equal(pspec->name, "password") || + g_str_equal(pspec->name, "ca-file")) { + g_object_set_property(G_OBJECT(session), pspec->name, &value); + } else if (g_str_equal(pspec->name, "sport")) { + g_object_set_property(G_OBJECT(session), "tls-port", &value); + } else if (g_str_equal(pspec->name, "tls-ciphers")) { + g_object_set_property(G_OBJECT(session), "ciphers", &value); + } else if (g_str_equal(pspec->name, "host-subject")) { + g_object_set_property(G_OBJECT(session), "cert-subject", &value); + } else if (g_str_equal(pspec->name, "title")) { + g_object_set_property(G_OBJECT(app), "title", &value); + } else if (g_str_equal(pspec->name, "display-flags")) { + guint flags = g_value_get_uint(&value); + gboolean fullscreen = flags & CONTROLLER_SET_FULL_SCREEN; + gboolean auto_res = flags & CONTROLLER_AUTO_DISPLAY_RES; + g_object_set(G_OBJECT(self), "fullscreen", fullscreen, NULL); + g_debug("unimplemented resize-guest %d", auto_res); + /* g_object_set(G_OBJECT(self), "resize-guest", auto_res, NULL); */ + } else if (g_str_equal(pspec->name, "menu")) { + spice_ctrl_menu_updated(self, g_value_get_object(&value)); + } else { + gchar *content = g_strdup_value_contents(&value); + + g_debug("unimplemented property: %s=%s", pspec->name, content); + g_free(content); + } + + g_object_unref(session); + g_value_unset(&value); } static void spice_ctrl_listen_async_cb(GObject *object, - GAsyncResult *res, - gpointer user_data) + GAsyncResult *res, + gpointer user_data) { - GError *error = NULL; + GError *error = NULL; - spice_ctrl_controller_listen_finish(SPICE_CTRL_CONTROLLER(object), res, &error); + spice_ctrl_controller_listen_finish(SPICE_CTRL_CONTROLLER(object), res, &error); - if (error != NULL) { - virt_viewer_app_simple_message_dialog(VIRT_VIEWER_APP(user_data), - _("Controller connection failed: %s"), - error->message); - g_clear_error(&error); - exit(1); /* TODO: make start async? */ - } + if (error != NULL) { + virt_viewer_app_simple_message_dialog(VIRT_VIEWER_APP(user_data), + _("Controller connection failed: %s"), + error->message); + g_clear_error(&error); + exit(1); /* TODO: make start async? */ + } } static int remote_viewer_activate(VirtViewerApp *app) { - g_return_val_if_fail(REMOTE_VIEWER_IS(app), -1); - RemoteViewer *self = REMOTE_VIEWER(app); - int ret = -1; - - if (self->priv->controller) { - SpiceSession *session = remote_viewer_get_spice_session(self); - ret = spice_session_connect(session); - g_object_unref(session); - } else { - ret = VIRT_VIEWER_APP_CLASS(remote_viewer_parent_class)->activate(app); - } - - return ret; + g_return_val_if_fail(REMOTE_VIEWER_IS(app), -1); + RemoteViewer *self = REMOTE_VIEWER(app); + int ret = -1; + + if (self->priv->controller) { + SpiceSession *session = remote_viewer_get_spice_session(self); + ret = spice_session_connect(session); + g_object_unref(session); + } else { + ret = VIRT_VIEWER_APP_CLASS(remote_viewer_parent_class)->activate(app); + } + + return ret; } #endif static void remote_viewer_window_added(VirtViewerApp *self G_GNUC_UNUSED, - VirtViewerWindow *win) + VirtViewerWindow *win) { - GtkMenuShell *shell = GTK_MENU_SHELL(gtk_builder_get_object(virt_viewer_window_get_builder(win), "top-menu")); - GtkWidget *spice = gtk_menu_item_new_with_label("Spice"); + GtkMenuShell *shell = GTK_MENU_SHELL(gtk_builder_get_object(virt_viewer_window_get_builder(win), "top-menu")); + GtkWidget *spice = gtk_menu_item_new_with_label("Spice"); - gtk_menu_shell_append(shell, spice); - g_object_set_data(G_OBJECT(win), "spice-menu", spice); + gtk_menu_shell_append(shell, spice); + g_object_set_data(G_OBJECT(win), "spice-menu", spice); } static gboolean remote_viewer_start(VirtViewerApp *app) { - g_return_val_if_fail(REMOTE_VIEWER_IS(app), FALSE); + g_return_val_if_fail(REMOTE_VIEWER_IS(app), FALSE); #if HAVE_SPICE_GTK - RemoteViewer *self = REMOTE_VIEWER(app); - RemoteViewerPrivate *priv = self->priv; + RemoteViewer *self = REMOTE_VIEWER(app); + RemoteViewerPrivate *priv = self->priv; #endif - gboolean ret = FALSE; - gchar *guri = NULL; - gchar *type = NULL; + gboolean ret = FALSE; + gchar *guri = NULL; + gchar *type = NULL; #if HAVE_SPICE_GTK - if (priv->controller) { - if (virt_viewer_app_create_session(app, "spice") < 0) { - virt_viewer_app_simple_message_dialog(app, _("Couldn't create a Spice session")); - goto cleanup; - } - - g_signal_connect(priv->controller, "notify", G_CALLBACK(spice_ctrl_notified), self); - g_signal_connect(priv->controller, "do_connect", G_CALLBACK(spice_ctrl_do_connect), self); - g_signal_connect(priv->controller, "show", G_CALLBACK(spice_ctrl_show), self); - g_signal_connect(priv->controller, "hide", G_CALLBACK(spice_ctrl_hide), self); - - spice_ctrl_controller_listen(priv->controller, NULL, spice_ctrl_listen_async_cb, self); - virt_viewer_app_show_status(VIRT_VIEWER_APP(self), _("Setting up Spice session...")); - } else { + if (priv->controller) { + if (virt_viewer_app_create_session(app, "spice") < 0) { + virt_viewer_app_simple_message_dialog(app, _("Couldn't create a Spice session")); + goto cleanup; + } + + g_signal_connect(priv->controller, "notify", G_CALLBACK(spice_ctrl_notified), self); + g_signal_connect(priv->controller, "do_connect", G_CALLBACK(spice_ctrl_do_connect), self); + g_signal_connect(priv->controller, "show", G_CALLBACK(spice_ctrl_show), self); + g_signal_connect(priv->controller, "hide", G_CALLBACK(spice_ctrl_hide), self); + + spice_ctrl_controller_listen(priv->controller, NULL, spice_ctrl_listen_async_cb, self); + virt_viewer_app_show_status(VIRT_VIEWER_APP(self), _("Setting up Spice session...")); + } else { #endif - g_object_get(app, "guri", &guri, NULL); - g_return_val_if_fail(guri != NULL, FALSE); - - DEBUG_LOG("Opening display to %s", guri); - g_object_set(app, "title", guri, NULL); - - if (virt_viewer_util_extract_host(guri, &type, NULL, NULL, NULL, NULL) < 0) { - virt_viewer_app_simple_message_dialog(app, _("Cannot determine the connection type from URI")); - goto cleanup; - } - - if (virt_viewer_app_create_session(app, type) < 0) { - virt_viewer_app_simple_message_dialog(app, _("Couldn't create a session for this type: %s"), type); - goto cleanup; - } - - if (virt_viewer_app_initial_connect(app) < 0) { - virt_viewer_app_simple_message_dialog(app, _("Failed to initiate connection")); - goto cleanup; - } + g_object_get(app, "guri", &guri, NULL); + g_return_val_if_fail(guri != NULL, FALSE); + + DEBUG_LOG("Opening display to %s", guri); + g_object_set(app, "title", guri, NULL); + + if (virt_viewer_util_extract_host(guri, &type, NULL, NULL, NULL, NULL) < 0) { + virt_viewer_app_simple_message_dialog(app, _("Cannot determine the connection type from URI")); + goto cleanup; + } + + if (virt_viewer_app_create_session(app, type) < 0) { + virt_viewer_app_simple_message_dialog(app, _("Couldn't create a session for this type: %s"), type); + goto cleanup; + } + + if (virt_viewer_app_initial_connect(app) < 0) { + virt_viewer_app_simple_message_dialog(app, _("Failed to initiate connection")); + goto cleanup; + } #if HAVE_SPICE_GTK - } + } #endif - ret = VIRT_VIEWER_APP_CLASS(remote_viewer_parent_class)->start(app); + ret = VIRT_VIEWER_APP_CLASS(remote_viewer_parent_class)->start(app); -cleanup: - g_free(guri); - g_free(type); - return ret; + cleanup: + g_free(guri); + g_free(type); + return ret; } /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 - * indent-tabs-mode: t + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/remote-viewer.h b/src/remote-viewer.h index 3d02315..444818f 100644 --- a/src/remote-viewer.h +++ b/src/remote-viewer.h @@ -38,12 +38,12 @@ G_BEGIN_DECLS typedef struct _RemoteViewerPrivate RemoteViewerPrivate; typedef struct { - VirtViewerApp parent; - RemoteViewerPrivate *priv; + VirtViewerApp parent; + RemoteViewerPrivate *priv; } RemoteViewer; typedef struct { - VirtViewerAppClass parent_class; + VirtViewerAppClass parent_class; } RemoteViewerClass; GType remote_viewer_get_type (void); @@ -54,3 +54,10 @@ RemoteViewer* remote_viewer_new_with_controller(gboolean verbose); G_END_DECLS #endif /* REMOTE_VIEWER_H */ +/* + * Local variables: + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/src/view/autoDrawer.c b/src/view/autoDrawer.c index 7242a02..cf9d2c4 100644 --- a/src/view/autoDrawer.c +++ b/src/view/autoDrawer.c @@ -257,7 +257,7 @@ ViewAutoDrawerUpdate(ViewAutoDrawer *that, // IN } #else if (window->group && window->group->grabs) { - grabbed = GTK_WIDGET(window->group->grabs->data); + grabbed = GTK_WIDGET(window->group->grabs->data); } #endif if (!grabbed) { @@ -440,7 +440,7 @@ ViewAutoDrawerOnSetFocus(GtkWindow *window G_GNUC_UNUSED, // IN static void ViewAutoDrawerOnHierarchyChanged(ViewAutoDrawer *that, // IN - GtkWidget *oldToplevel) // IN + GtkWidget *oldToplevel) // IN { GtkWidget *newToplevel = gtk_widget_get_toplevel(GTK_WIDGET(that)); @@ -689,7 +689,7 @@ ViewAutoDrawer_GetType(void) sizeof (ViewAutoDrawer), 0, /* n_preallocs */ (GInstanceInitFunc)ViewAutoDrawerInit, - NULL, + NULL, }; type = g_type_register_static(VIEW_TYPE_DRAWER, "ViewAutoDrawer", &info, 0); diff --git a/src/view/drawer.c b/src/view/drawer.c index 989b5ca..c74b902 100644 --- a/src/view/drawer.c +++ b/src/view/drawer.c @@ -175,7 +175,7 @@ ViewDrawer_GetType(void) sizeof (ViewDrawer), 0, /* n_preallocs */ (GInstanceInitFunc)ViewDrawerInit, - NULL + NULL }; type = g_type_register_static(VIEW_TYPE_OV_BOX, "ViewDrawer", &info, 0); diff --git a/src/view/ovBox.c b/src/view/ovBox.c index 1d6733f..e815f1b 100644 --- a/src/view/ovBox.c +++ b/src/view/ovBox.c @@ -76,9 +76,9 @@ #include "ovBox.h" #if ! GTK_CHECK_VERSION(3, 0, 0) -#define gtk_widget_set_realized(widget, val) \ +#define gtk_widget_set_realized(widget, val) \ GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED) -#define gtk_widget_get_realized(widget) \ +#define gtk_widget_get_realized(widget) \ GTK_WIDGET_REALIZED(widget) #endif @@ -763,7 +763,7 @@ ViewOvBox_GetType(void) sizeof (ViewOvBox), 0, /* n_preallocs */ (GInstanceInitFunc)ViewOvBoxInit, - NULL, + NULL, }; type = g_type_register_static(GTK_TYPE_BOX, "ViewOvBox", &info, 0); diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c index f14e46b..6f532b4 100644 --- a/src/virt-viewer-app.c +++ b/src/virt-viewer-app.c @@ -70,91 +70,91 @@ void virt_viewer_app_about_delete(GtkWidget *dialog, void *dummy, VirtViewerApp /* Internal methods */ static void virt_viewer_app_connected(VirtViewerSession *session, - VirtViewerApp *self); + VirtViewerApp *self); static void virt_viewer_app_initialized(VirtViewerSession *session, - VirtViewerApp *self); + VirtViewerApp *self); static void virt_viewer_app_disconnected(VirtViewerSession *session, - VirtViewerApp *self); + VirtViewerApp *self); static void virt_viewer_app_auth_refused(VirtViewerSession *session, - const char *msg, - VirtViewerApp *self); + const char *msg, + VirtViewerApp *self); static void virt_viewer_app_auth_failed(VirtViewerSession *session, - const char *msg, - VirtViewerApp *self); + const char *msg, + VirtViewerApp *self); static void virt_viewer_app_usb_failed(VirtViewerSession *session, - const char *msg, - VirtViewerApp *self); + const char *msg, + VirtViewerApp *self); static void virt_viewer_app_server_cut_text(VirtViewerSession *session, - const gchar *text, - VirtViewerApp *self); + const gchar *text, + VirtViewerApp *self); static void virt_viewer_app_bell(VirtViewerSession *session, - VirtViewerApp *self); + VirtViewerApp *self); static void virt_viewer_app_cancelled(VirtViewerSession *session, - VirtViewerApp *self); + VirtViewerApp *self); static void virt_viewer_app_channel_open(VirtViewerSession *session, - VirtViewerSessionChannel *channel, - VirtViewerApp *self); + VirtViewerSessionChannel *channel, + VirtViewerApp *self); static void virt_viewer_app_update_pretty_address(VirtViewerApp *self); static void virt_viewer_app_set_fullscreen(VirtViewerApp *self, gboolean fullscreen); static void virt_viewer_app_update_menu_displays(VirtViewerApp *self); struct _VirtViewerAppPrivate { - VirtViewerWindow *main_window; - GtkWidget *main_notebook; - GtkWidget *container; - GHashTable *windows; - gchar *clipboard; - - gboolean direct; - gboolean verbose; - gboolean authretry; - gboolean started; - gboolean fullscreen; - gboolean attach; - - VirtViewerSession *session; - gboolean active; - gboolean connected; - gboolean cancelled; - guint reconnect_poll; /* source id */ - char *unixsock; - char *guri; /* prefered over ghost:gport */ - char *ghost; - char *gport; - char *host; /* ssh */ - int port;/* ssh */ - char *user; /* ssh */ - char *transport; - char *pretty_address; - gchar *guest_name; - gboolean grabbed; - char *title; + VirtViewerWindow *main_window; + GtkWidget *main_notebook; + GtkWidget *container; + GHashTable *windows; + gchar *clipboard; + + gboolean direct; + gboolean verbose; + gboolean authretry; + gboolean started; + gboolean fullscreen; + gboolean attach; + + VirtViewerSession *session; + gboolean active; + gboolean connected; + gboolean cancelled; + guint reconnect_poll; /* source id */ + char *unixsock; + char *guri; /* prefered over ghost:gport */ + char *ghost; + char *gport; + char *host; /* ssh */ + int port;/* ssh */ + char *user; /* ssh */ + char *transport; + char *pretty_address; + gchar *guest_name; + gboolean grabbed; + char *title; }; G_DEFINE_ABSTRACT_TYPE(VirtViewerApp, virt_viewer_app, G_TYPE_OBJECT) -#define GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), VIRT_VIEWER_TYPE_APP, VirtViewerAppPrivate)) +#define GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), VIRT_VIEWER_TYPE_APP, VirtViewerAppPrivate)) enum { - PROP_0, - PROP_VERBOSE, - PROP_CONTAINER, - PROP_SESSION, - PROP_GUEST_NAME, - PROP_GURI, - PROP_FULLSCREEN, - PROP_TITLE, + PROP_0, + PROP_VERBOSE, + PROP_CONTAINER, + PROP_SESSION, + PROP_GUEST_NAME, + PROP_GURI, + PROP_FULLSCREEN, + PROP_TITLE, }; enum { - SIGNAL_WINDOW_ADDED, - SIGNAL_WINDOW_REMOVED, - SIGNAL_LAST, + SIGNAL_WINDOW_ADDED, + SIGNAL_WINDOW_REMOVED, + SIGNAL_LAST, }; static guint signals[SIGNAL_LAST]; @@ -162,135 +162,135 @@ static guint signals[SIGNAL_LAST]; void virt_viewer_app_set_debug(gboolean debug) { - doDebug = debug; + doDebug = debug; } void virt_viewer_app_simple_message_dialog(VirtViewerApp *self, - const char *fmt, ...) + const char *fmt, ...) { - g_return_if_fail(VIRT_VIEWER_IS_APP(self)); - GtkWindow *window = GTK_WINDOW(virt_viewer_window_get_window(self->priv->main_window)); - GtkWidget *dialog; - char *msg; - va_list vargs; + g_return_if_fail(VIRT_VIEWER_IS_APP(self)); + GtkWindow *window = GTK_WINDOW(virt_viewer_window_get_window(self->priv->main_window)); + GtkWidget *dialog; + char *msg; + va_list vargs; - va_start(vargs, fmt); + va_start(vargs, fmt); - msg = g_strdup_vprintf(fmt, vargs); + msg = g_strdup_vprintf(fmt, vargs); - va_end(vargs); + va_end(vargs); - dialog = gtk_message_dialog_new(window, - GTK_DIALOG_MODAL | - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - "%s", - msg); + dialog = gtk_message_dialog_new(window, + GTK_DIALOG_MODAL | + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + "%s", + msg); - gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); + gtk_widget_destroy(dialog); - g_free(msg); + g_free(msg); } void virt_viewer_app_quit(VirtViewerApp *self) { - g_return_if_fail(VIRT_VIEWER_IS_APP(self)); - VirtViewerAppPrivate *priv = self->priv; + g_return_if_fail(VIRT_VIEWER_IS_APP(self)); + VirtViewerAppPrivate *priv = self->priv; - if (priv->session) - virt_viewer_session_close(VIRT_VIEWER_SESSION(priv->session)); - gtk_main_quit(); + if (priv->session) + virt_viewer_session_close(VIRT_VIEWER_SESSION(priv->session)); + gtk_main_quit(); } static void count_window_visible(gpointer key G_GNUC_UNUSED, - gpointer value, - gpointer user_data) + gpointer value, + gpointer user_data) { - GtkWindow *win = virt_viewer_window_get_window(VIRT_VIEWER_WINDOW(value)); - guint *n = (guint*)user_data; + GtkWindow *win = virt_viewer_window_get_window(VIRT_VIEWER_WINDOW(value)); + guint *n = (guint*)user_data; - if (gtk_widget_get_visible(GTK_WIDGET(win))) - *n += 1; + if (gtk_widget_get_visible(GTK_WIDGET(win))) + *n += 1; } static guint virt_viewer_app_get_n_windows_visible(VirtViewerApp *self) { - guint n = 0; - g_hash_table_foreach(self->priv->windows, count_window_visible, &n); - return n; + guint n = 0; + g_hash_table_foreach(self->priv->windows, count_window_visible, &n); + return n; } static guint virt_viewer_app_get_n_windows(VirtViewerApp *self) { - return g_hash_table_size(self->priv->windows); + return g_hash_table_size(self->priv->windows); } gboolean virt_viewer_app_window_set_visible(VirtViewerApp *self, - VirtViewerWindow *vwin, - gboolean visible) -{ - GtkWidget *window; - g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), FALSE); - g_return_val_if_fail(VIRT_VIEWER_IS_WINDOW(vwin), FALSE); - - window = GTK_WIDGET(virt_viewer_window_get_window(vwin)); - if (visible) { - gtk_widget_show(window); - return TRUE; - } else { - if (virt_viewer_app_get_n_windows_visible(self) > 1) { - gtk_widget_hide(window); - return FALSE; - } else if (virt_viewer_app_get_n_windows(self) > 1) { - GtkWidget *dialog = - gtk_message_dialog_new (GTK_WINDOW(window), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_OK_CANCEL, - _("This is the last visible display. Do you want to quit?")); - gint result = gtk_dialog_run (GTK_DIALOG (dialog)); - switch (result) { - case GTK_RESPONSE_OK: - virt_viewer_app_quit(self); - break; - default: - break; - } - gtk_widget_destroy(dialog); - return FALSE; - } else { - virt_viewer_app_quit(self); - return FALSE; - } - } - - g_warn_if_reached(); - return FALSE; + VirtViewerWindow *vwin, + gboolean visible) +{ + GtkWidget *window; + g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), FALSE); + g_return_val_if_fail(VIRT_VIEWER_IS_WINDOW(vwin), FALSE); + + window = GTK_WIDGET(virt_viewer_window_get_window(vwin)); + if (visible) { + gtk_widget_show(window); + return TRUE; + } else { + if (virt_viewer_app_get_n_windows_visible(self) > 1) { + gtk_widget_hide(window); + return FALSE; + } else if (virt_viewer_app_get_n_windows(self) > 1) { + GtkWidget *dialog = + gtk_message_dialog_new (GTK_WINDOW(window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_OK_CANCEL, + _("This is the last visible display. Do you want to quit?")); + gint result = gtk_dialog_run (GTK_DIALOG (dialog)); + switch (result) { + case GTK_RESPONSE_OK: + virt_viewer_app_quit(self); + break; + default: + break; + } + gtk_widget_destroy(dialog); + return FALSE; + } else { + virt_viewer_app_quit(self); + return FALSE; + } + } + + g_warn_if_reached(); + return FALSE; } G_MODULE_EXPORT void virt_viewer_app_about_close(GtkWidget *dialog, - VirtViewerApp *self G_GNUC_UNUSED) + VirtViewerApp *self G_GNUC_UNUSED) { - gtk_widget_hide(dialog); - gtk_widget_destroy(dialog); + gtk_widget_hide(dialog); + gtk_widget_destroy(dialog); } G_MODULE_EXPORT void virt_viewer_app_about_delete(GtkWidget *dialog, - void *dummy G_GNUC_UNUSED, - VirtViewerApp *self G_GNUC_UNUSED) + void *dummy G_GNUC_UNUSED, + VirtViewerApp *self G_GNUC_UNUSED) { - gtk_widget_hide(dialog); - gtk_widget_destroy(dialog); + gtk_widget_hide(dialog); + gtk_widget_destroy(dialog); } #if defined(HAVE_SOCKETPAIR) && defined(HAVE_FORK) @@ -298,1350 +298,1349 @@ virt_viewer_app_about_delete(GtkWidget *dialog, static int virt_viewer_app_open_tunnel(const char **cmd) { - int fd[2]; - pid_t pid; + int fd[2]; + pid_t pid; - if (socketpair(PF_UNIX, SOCK_STREAM, 0, fd) < 0) - return -1; + if (socketpair(PF_UNIX, SOCK_STREAM, 0, fd) < 0) + return -1; - pid = fork(); - if (pid == -1) { - close(fd[0]); - close(fd[1]); - return -1; - } + pid = fork(); + if (pid == -1) { + close(fd[0]); + close(fd[1]); + return -1; + } - if (pid == 0) { /* child */ - close(fd[0]); - close(0); - close(1); - if (dup(fd[1]) < 0) - _exit(1); - if (dup(fd[1]) < 0) - _exit(1); - close(fd[1]); - execvp("ssh", (char *const*)cmd); - _exit(1); - } - close(fd[1]); - return fd[0]; + if (pid == 0) { /* child */ + close(fd[0]); + close(0); + close(1); + if (dup(fd[1]) < 0) + _exit(1); + if (dup(fd[1]) < 0) + _exit(1); + close(fd[1]); + execvp("ssh", (char *const*)cmd); + _exit(1); + } + close(fd[1]); + return fd[0]; } static int virt_viewer_app_open_tunnel_ssh(const char *sshhost, - int sshport, - const char *sshuser, - const char *host, - const char *port, - const char *unixsock) -{ - const char *cmd[10]; - char portstr[50]; - int n = 0; - - cmd[n++] = "ssh"; - if (sshport) { - cmd[n++] = "-p"; - sprintf(portstr, "%d", sshport); - cmd[n++] = portstr; - } - if (sshuser) { - cmd[n++] = "-l"; - cmd[n++] = sshuser; - } - cmd[n++] = sshhost; - cmd[n++] = "nc"; - if (port) { - cmd[n++] = host; - cmd[n++] = port; - } else { - cmd[n++] = "-U"; - cmd[n++] = unixsock; - } - cmd[n++] = NULL; - - return virt_viewer_app_open_tunnel(cmd); + int sshport, + const char *sshuser, + const char *host, + const char *port, + const char *unixsock) +{ + const char *cmd[10]; + char portstr[50]; + int n = 0; + + cmd[n++] = "ssh"; + if (sshport) { + cmd[n++] = "-p"; + sprintf(portstr, "%d", sshport); + cmd[n++] = portstr; + } + if (sshuser) { + cmd[n++] = "-l"; + cmd[n++] = sshuser; + } + cmd[n++] = sshhost; + cmd[n++] = "nc"; + if (port) { + cmd[n++] = host; + cmd[n++] = port; + } else { + cmd[n++] = "-U"; + cmd[n++] = unixsock; + } + cmd[n++] = NULL; + + return virt_viewer_app_open_tunnel(cmd); } static int virt_viewer_app_open_unix_sock(const char *unixsock) { - struct sockaddr_un addr; - int fd; + struct sockaddr_un addr; + int fd; - memset(&addr, 0, sizeof addr); - addr.sun_family = AF_UNIX; - strcpy(addr.sun_path, unixsock); + memset(&addr, 0, sizeof addr); + addr.sun_family = AF_UNIX; + strcpy(addr.sun_path, unixsock); - if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) - return -1; + if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) + return -1; - if (connect(fd, (struct sockaddr *)&addr, sizeof addr) < 0) { - close(fd); - return -1; - } + if (connect(fd, (struct sockaddr *)&addr, sizeof addr) < 0) { + close(fd); + return -1; + } - return fd; + return fd; } #endif /* defined(HAVE_SOCKETPAIR) && defined(HAVE_FORK) */ void virt_viewer_app_trace(VirtViewerApp *self, - const char *fmt, ...) + const char *fmt, ...) { - g_return_if_fail(VIRT_VIEWER_IS_APP(self)); - va_list ap; - VirtViewerAppPrivate *priv = self->priv; + g_return_if_fail(VIRT_VIEWER_IS_APP(self)); + va_list ap; + VirtViewerAppPrivate *priv = self->priv; - if (doDebug) { - va_start(ap, fmt); - g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, fmt, ap); - va_end(ap); - } + if (doDebug) { + va_start(ap, fmt); + g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, fmt, ap); + va_end(ap); + } - if (priv->verbose) { - va_start(ap, fmt); - g_vprintf(fmt, ap); - va_end(ap); - } + if (priv->verbose) { + va_start(ap, fmt); + g_vprintf(fmt, ap); + va_end(ap); + } } static void virt_viewer_app_set_window_subtitle(VirtViewerApp *app, - VirtViewerWindow *window, - int nth) + VirtViewerWindow *window, + int nth) { - gchar *subtitle = app->priv->title ? g_strdup_printf("%s (%d)", app->priv->title, nth + 1) : NULL; - g_object_set(window, "subtitle", subtitle, NULL); - g_free(subtitle); + gchar *subtitle = app->priv->title ? g_strdup_printf("%s (%d)", app->priv->title, nth + 1) : NULL; + g_object_set(window, "subtitle", subtitle, NULL); + g_free(subtitle); } static void set_title(gpointer key, - gpointer value, - gpointer user_data) + gpointer value, + gpointer user_data) { - gint *nth = key; - VirtViewerApp *app = user_data; - VirtViewerWindow *window = value; - virt_viewer_app_set_window_subtitle(app, window, *nth); + gint *nth = key; + VirtViewerApp *app = user_data; + VirtViewerWindow *window = value; + virt_viewer_app_set_window_subtitle(app, window, *nth); } static void virt_viewer_app_set_all_window_subtitles(VirtViewerApp *app) { - virt_viewer_app_set_window_subtitle(app, app->priv->main_window, 0); - g_hash_table_foreach(app->priv->windows, set_title, app); + virt_viewer_app_set_window_subtitle(app, app->priv->main_window, 0); + g_hash_table_foreach(app->priv->windows, set_title, app); } static void update_title(gpointer key G_GNUC_UNUSED, - gpointer value, - gpointer user_data G_GNUC_UNUSED) + gpointer value, + gpointer user_data G_GNUC_UNUSED) { - virt_viewer_window_update_title(VIRT_VIEWER_WINDOW(value)); + virt_viewer_window_update_title(VIRT_VIEWER_WINDOW(value)); } static void virt_viewer_app_update_title(VirtViewerApp *self) { - g_hash_table_foreach(self->priv->windows, update_title, NULL); + g_hash_table_foreach(self->priv->windows, update_title, NULL); } static void set_usb_options_sensitive(gpointer key G_GNUC_UNUSED, - gpointer value, - gpointer user_data) + gpointer value, + gpointer user_data) { - virt_viewer_window_set_usb_options_sensitive( - VIRT_VIEWER_WINDOW(value), GPOINTER_TO_INT(user_data)); + virt_viewer_window_set_usb_options_sensitive( + VIRT_VIEWER_WINDOW(value), GPOINTER_TO_INT(user_data)); } static void virt_viewer_app_set_usb_options_sensitive(VirtViewerApp *self, gboolean sensitive) { - g_hash_table_foreach(self->priv->windows, set_usb_options_sensitive, - GINT_TO_POINTER(sensitive)); + g_hash_table_foreach(self->priv->windows, set_usb_options_sensitive, + GINT_TO_POINTER(sensitive)); } static VirtViewerWindow * virt_viewer_app_get_nth_window(VirtViewerApp *self, gint nth) { - return g_hash_table_lookup(self->priv->windows, &nth); + return g_hash_table_lookup(self->priv->windows, &nth); } static gboolean virt_viewer_app_remove_nth_window(VirtViewerApp *self, gint nth) { - VirtViewerWindow *win; - gboolean removed; + VirtViewerWindow *win; + gboolean removed; - g_return_val_if_fail(nth != 0, FALSE); + g_return_val_if_fail(nth != 0, FALSE); - win = virt_viewer_app_get_nth_window(self, nth); - g_return_val_if_fail(win != NULL, FALSE); + win = virt_viewer_app_get_nth_window(self, nth); + g_return_val_if_fail(win != NULL, FALSE); - removed = g_hash_table_steal(self->priv->windows, &nth); - g_warn_if_fail(removed); + removed = g_hash_table_steal(self->priv->windows, &nth); + g_warn_if_fail(removed); - if (removed) - g_signal_emit(self, signals[SIGNAL_WINDOW_REMOVED], 0, win); + if (removed) + g_signal_emit(self, signals[SIGNAL_WINDOW_REMOVED], 0, win); - g_object_unref(win); + g_object_unref(win); - return removed; + return removed; } static void virt_viewer_app_set_nth_window(VirtViewerApp *self, gint nth, VirtViewerWindow *win) { - gint *key; + gint *key; - g_return_if_fail(virt_viewer_app_get_nth_window(self, nth) == NULL); - key = g_malloc(sizeof(gint)); - *key = nth; - g_hash_table_insert(self->priv->windows, key, win); - virt_viewer_app_set_window_subtitle(self, win, nth); + g_return_if_fail(virt_viewer_app_get_nth_window(self, nth) == NULL); + key = g_malloc(sizeof(gint)); + *key = nth; + g_hash_table_insert(self->priv->windows, key, win); + virt_viewer_app_set_window_subtitle(self, win, nth); - g_signal_emit(self, signals[SIGNAL_WINDOW_ADDED], 0, win); + g_signal_emit(self, signals[SIGNAL_WINDOW_ADDED], 0, win); } static void viewer_window_visible_cb(GtkWidget *widget G_GNUC_UNUSED, - gpointer user_data) + gpointer user_data) { - virt_viewer_app_update_menu_displays(VIRT_VIEWER_APP(user_data)); + virt_viewer_app_update_menu_displays(VIRT_VIEWER_APP(user_data)); } static VirtViewerWindow* virt_viewer_app_window_new(VirtViewerApp *self, GtkWidget *container, gint nth) { - VirtViewerWindow* window; - GtkWindow *w; + VirtViewerWindow* window; + GtkWindow *w; - window = g_object_new(VIRT_VIEWER_TYPE_WINDOW, - "app", self, - "container", container, - NULL); - if (self->priv->main_window) - virt_viewer_window_set_zoom_level(window, virt_viewer_window_get_zoom_level(self->priv->main_window)); - virt_viewer_app_set_nth_window(self, nth, window); - w = virt_viewer_window_get_window(window); + window = g_object_new(VIRT_VIEWER_TYPE_WINDOW, + "app", self, + "container", container, + NULL); + if (self->priv->main_window) + virt_viewer_window_set_zoom_level(window, virt_viewer_window_get_zoom_level(self->priv->main_window)); + virt_viewer_app_set_nth_window(self, nth, window); + w = virt_viewer_window_get_window(window); - /* this will set new window to fullscreen if necessary */ - virt_viewer_app_set_fullscreen(self, self->priv->fullscreen); - g_signal_connect(w, "hide", G_CALLBACK(viewer_window_visible_cb), self); - g_signal_connect(w, "show", G_CALLBACK(viewer_window_visible_cb), self); - return window; + /* this will set new window to fullscreen if necessary */ + virt_viewer_app_set_fullscreen(self, self->priv->fullscreen); + g_signal_connect(w, "hide", G_CALLBACK(viewer_window_visible_cb), self); + g_signal_connect(w, "show", G_CALLBACK(viewer_window_visible_cb), self); + return window; } static void display_show_hint(VirtViewerDisplay *display, - GParamSpec *pspec G_GNUC_UNUSED, - VirtViewerWindow *win) -{ - VirtViewerApp *self; - VirtViewerNotebook *nb = virt_viewer_window_get_notebook(win); - GtkWindow *w = virt_viewer_window_get_window(win); - gint nth, hint; - - g_object_get(win, - "app", &self, - NULL); - g_object_get(display, - "nth-display", &nth, - "show-hint", &hint, - NULL); - - if (hint == VIRT_VIEWER_DISPLAY_SHOW_HINT_HIDE) { - if (win != self->priv->main_window && - g_getenv("VIRT_VIEWER_HIDE")) - gtk_widget_hide(GTK_WIDGET(w)); - virt_viewer_notebook_show_status(nb, _("Waiting for display %d..."), nth + 1); - } else { - virt_viewer_notebook_show_display(nb); - gtk_widget_show(GTK_WIDGET(w)); - gtk_window_present(w); - } - - g_object_unref(self); + GParamSpec *pspec G_GNUC_UNUSED, + VirtViewerWindow *win) +{ + VirtViewerApp *self; + VirtViewerNotebook *nb = virt_viewer_window_get_notebook(win); + GtkWindow *w = virt_viewer_window_get_window(win); + gint nth, hint; + + g_object_get(win, + "app", &self, + NULL); + g_object_get(display, + "nth-display", &nth, + "show-hint", &hint, + NULL); + + if (hint == VIRT_VIEWER_DISPLAY_SHOW_HINT_HIDE) { + if (win != self->priv->main_window && + g_getenv("VIRT_VIEWER_HIDE")) + gtk_widget_hide(GTK_WIDGET(w)); + virt_viewer_notebook_show_status(nb, _("Waiting for display %d..."), nth + 1); + } else { + virt_viewer_notebook_show_display(nb); + gtk_widget_show(GTK_WIDGET(w)); + gtk_window_present(w); + } + + g_object_unref(self); } static void virt_viewer_app_display_added(VirtViewerSession *session G_GNUC_UNUSED, - VirtViewerDisplay *display, - VirtViewerApp *self) -{ - VirtViewerAppPrivate *priv = self->priv; - VirtViewerWindow *window; - gint nth; - - g_object_get(display, "nth-display", &nth, NULL); - if (nth == 0) { - window = priv->main_window; - } else { - if (priv->container) { - g_warning("multi-head not yet supported within container"); - return; - } + VirtViewerDisplay *display, + VirtViewerApp *self) +{ + VirtViewerAppPrivate *priv = self->priv; + VirtViewerWindow *window; + gint nth; + + g_object_get(display, "nth-display", &nth, NULL); + if (nth == 0) { + window = priv->main_window; + } else { + if (priv->container) { + g_warning("multi-head not yet supported within container"); + return; + } - g_return_if_fail(virt_viewer_app_get_nth_window(self, nth) == NULL); - window = virt_viewer_app_window_new(self, NULL, nth); - } + g_return_if_fail(virt_viewer_app_get_nth_window(self, nth) == NULL); + window = virt_viewer_app_window_new(self, NULL, nth); + } - virt_viewer_window_set_display(window, display); - g_signal_connect(display, "notify::show-hint", - G_CALLBACK(display_show_hint), window); - g_object_notify(G_OBJECT(display), "show-hint"); /* call display_show_hint */ + virt_viewer_window_set_display(window, display); + g_signal_connect(display, "notify::show-hint", + G_CALLBACK(display_show_hint), window); + g_object_notify(G_OBJECT(display), "show-hint"); /* call display_show_hint */ } static void virt_viewer_app_display_removed(VirtViewerSession *session G_GNUC_UNUSED, - VirtViewerDisplay *display, - VirtViewerApp *self) + VirtViewerDisplay *display, + VirtViewerApp *self) { - VirtViewerWindow *win = NULL; - gint nth; + VirtViewerWindow *win = NULL; + gint nth; - gtk_widget_hide(GTK_WIDGET(display)); - g_object_get(display, "nth-display", &nth, NULL); - win = virt_viewer_app_get_nth_window(self, nth); - virt_viewer_window_set_display(win, NULL); + gtk_widget_hide(GTK_WIDGET(display)); + g_object_get(display, "nth-display", &nth, NULL); + win = virt_viewer_app_get_nth_window(self, nth); + virt_viewer_window_set_display(win, NULL); - if (nth != 0) - virt_viewer_app_remove_nth_window(self, nth); + if (nth != 0) + virt_viewer_app_remove_nth_window(self, nth); } int virt_viewer_app_create_session(VirtViewerApp *self, const gchar *type) { - g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), -1); - VirtViewerAppPrivate *priv = self->priv; - g_return_val_if_fail(priv->session == NULL, -1); + g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), -1); + VirtViewerAppPrivate *priv = self->priv; + g_return_val_if_fail(priv->session == NULL, -1); #ifdef HAVE_GTK_VNC - if (g_ascii_strcasecmp(type, "vnc") == 0) { - virt_viewer_app_trace(self, "Guest %s has a %s display\n", - priv->guest_name, type); - priv->session = virt_viewer_session_vnc_new(); - } else + if (g_ascii_strcasecmp(type, "vnc") == 0) { + virt_viewer_app_trace(self, "Guest %s has a %s display\n", + priv->guest_name, type); + priv->session = virt_viewer_session_vnc_new(); + } else #endif #ifdef HAVE_SPICE_GTK - if (g_ascii_strcasecmp(type, "spice") == 0) { - virt_viewer_app_trace(self, "Guest %s has a %s display\n", - priv->guest_name, type); - priv->session = virt_viewer_session_spice_new(); - } else + if (g_ascii_strcasecmp(type, "spice") == 0) { + virt_viewer_app_trace(self, "Guest %s has a %s display\n", + priv->guest_name, type); + priv->session = virt_viewer_session_spice_new(); + } else #endif - { - virt_viewer_app_trace(self, "Guest %s has unsupported %s display type\n", - priv->guest_name, type); - virt_viewer_app_simple_message_dialog(self, _("Unknown graphic type for the guest %s"), - priv->guest_name); - return -1; - } - - g_signal_connect(priv->session, "session-initialized", - G_CALLBACK(virt_viewer_app_initialized), self); - g_signal_connect(priv->session, "session-connected", - G_CALLBACK(virt_viewer_app_connected), self); - g_signal_connect(priv->session, "session-disconnected", - G_CALLBACK(virt_viewer_app_disconnected), self); - g_signal_connect(priv->session, "session-channel-open", - G_CALLBACK(virt_viewer_app_channel_open), self); - g_signal_connect(priv->session, "session-auth-refused", - G_CALLBACK(virt_viewer_app_auth_refused), self); - g_signal_connect(priv->session, "session-auth-failed", - G_CALLBACK(virt_viewer_app_auth_failed), self); - g_signal_connect(priv->session, "session-usb-failed", - G_CALLBACK(virt_viewer_app_usb_failed), self); - g_signal_connect(priv->session, "session-display-added", - G_CALLBACK(virt_viewer_app_display_added), self); - g_signal_connect(priv->session, "session-display-removed", - G_CALLBACK(virt_viewer_app_display_removed), self); - - g_signal_connect(priv->session, "session-cut-text", - G_CALLBACK(virt_viewer_app_server_cut_text), self); - g_signal_connect(priv->session, "session-bell", - G_CALLBACK(virt_viewer_app_bell), self); - g_signal_connect(priv->session, "session-cancelled", - G_CALLBACK(virt_viewer_app_cancelled), self); - - return 0; + { + virt_viewer_app_trace(self, "Guest %s has unsupported %s display type\n", + priv->guest_name, type); + virt_viewer_app_simple_message_dialog(self, _("Unknown graphic type for the guest %s"), + priv->guest_name); + return -1; + } + + g_signal_connect(priv->session, "session-initialized", + G_CALLBACK(virt_viewer_app_initialized), self); + g_signal_connect(priv->session, "session-connected", + G_CALLBACK(virt_viewer_app_connected), self); + g_signal_connect(priv->session, "session-disconnected", + G_CALLBACK(virt_viewer_app_disconnected), self); + g_signal_connect(priv->session, "session-channel-open", + G_CALLBACK(virt_viewer_app_channel_open), self); + g_signal_connect(priv->session, "session-auth-refused", + G_CALLBACK(virt_viewer_app_auth_refused), self); + g_signal_connect(priv->session, "session-auth-failed", + G_CALLBACK(virt_viewer_app_auth_failed), self); + g_signal_connect(priv->session, "session-usb-failed", + G_CALLBACK(virt_viewer_app_usb_failed), self); + g_signal_connect(priv->session, "session-display-added", + G_CALLBACK(virt_viewer_app_display_added), self); + g_signal_connect(priv->session, "session-display-removed", + G_CALLBACK(virt_viewer_app_display_removed), self); + + g_signal_connect(priv->session, "session-cut-text", + G_CALLBACK(virt_viewer_app_server_cut_text), self); + g_signal_connect(priv->session, "session-bell", + G_CALLBACK(virt_viewer_app_bell), self); + g_signal_connect(priv->session, "session-cancelled", + G_CALLBACK(virt_viewer_app_cancelled), self); + + return 0; } static gboolean virt_viewer_app_default_open_connection(VirtViewerApp *self G_GNUC_UNUSED, int *fd) { - *fd = -1; - return TRUE; + *fd = -1; + return TRUE; } static int virt_viewer_app_open_connection(VirtViewerApp *self, int *fd) { - VirtViewerAppClass *klass; + VirtViewerAppClass *klass; - g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), -1); - klass = VIRT_VIEWER_APP_GET_CLASS(self); + g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), -1); + klass = VIRT_VIEWER_APP_GET_CLASS(self); - return klass->open_connection(self, fd); + return klass->open_connection(self, fd); } #if defined(HAVE_SOCKETPAIR) && defined(HAVE_FORK) static void virt_viewer_app_channel_open(VirtViewerSession *session, - VirtViewerSessionChannel *channel, - VirtViewerApp *self) + VirtViewerSessionChannel *channel, + VirtViewerApp *self) { - VirtViewerAppPrivate *priv; - int fd = -1; + VirtViewerAppPrivate *priv; + int fd = -1; - g_return_if_fail(self != NULL); + g_return_if_fail(self != NULL); - if (!virt_viewer_app_open_connection(self, &fd)) - return; + if (!virt_viewer_app_open_connection(self, &fd)) + return; - DEBUG_LOG("After open connection callback fd=%d", fd); + DEBUG_LOG("After open connection callback fd=%d", fd); - priv = self->priv; - if (priv->transport && g_ascii_strcasecmp(priv->transport, "ssh") == 0 && - !priv->direct && fd == -1) { - if ((fd = virt_viewer_app_open_tunnel_ssh(priv->host, priv->port, priv->user, - priv->ghost, priv->gport, NULL)) < 0) - virt_viewer_app_simple_message_dialog(self, _("Connect to ssh failed.")); - } else if (fd == -1) { - virt_viewer_app_simple_message_dialog(self, _("Can't connect to channel, SSH only supported.")); - } + priv = self->priv; + if (priv->transport && g_ascii_strcasecmp(priv->transport, "ssh") == 0 && + !priv->direct && fd == -1) { + if ((fd = virt_viewer_app_open_tunnel_ssh(priv->host, priv->port, priv->user, + priv->ghost, priv->gport, NULL)) < 0) + virt_viewer_app_simple_message_dialog(self, _("Connect to ssh failed.")); + } else if (fd == -1) { + virt_viewer_app_simple_message_dialog(self, _("Can't connect to channel, SSH only supported.")); + } - if (fd >= 0) - virt_viewer_session_channel_open_fd(session, channel, fd); + if (fd >= 0) + virt_viewer_session_channel_open_fd(session, channel, fd); } #else static void virt_viewer_app_channel_open(VirtViewerSession *session G_GNUC_UNUSED, - VirtViewerSessionChannel *channel G_GNUC_UNUSED, - VirtViewerApp *self) + VirtViewerSessionChannel *channel G_GNUC_UNUSED, + VirtViewerApp *self) { - virt_viewer_app_simple_message_dialog(self, _("Connect to channel unsupported.")); + virt_viewer_app_simple_message_dialog(self, _("Connect to channel unsupported.")); } #endif static int virt_viewer_app_default_activate(VirtViewerApp *self) { - VirtViewerAppPrivate *priv = self->priv; - int fd = -1; + VirtViewerAppPrivate *priv = self->priv; + int fd = -1; - if (!virt_viewer_app_open_connection(self, &fd)) - return -1; + if (!virt_viewer_app_open_connection(self, &fd)) + return -1; - DEBUG_LOG("After open connection callback fd=%d", fd); + DEBUG_LOG("After open connection callback fd=%d", fd); #if defined(HAVE_SOCKETPAIR) && defined(HAVE_FORK) - if (priv->transport && - g_ascii_strcasecmp(priv->transport, "ssh") == 0 && - !priv->direct && - fd == -1) { - gchar *p = NULL; - - if (priv->gport) { - virt_viewer_app_trace(self, "Opening indirect TCP connection to display at %s:%s\n", - priv->ghost, priv->gport); - } else { - virt_viewer_app_trace(self, "Opening indirect UNIX connection to display at %s\n", - priv->unixsock); - } - if (priv->port) - p = g_strdup_printf(":%d", priv->port); - - virt_viewer_app_trace(self, "Setting up SSH tunnel via %s%s%s%s\n", - priv->user ? priv->user : "", - priv->user ? "@" : "", - priv->host, p ? p : ""); - g_free(p); - - if ((fd = virt_viewer_app_open_tunnel_ssh(priv->host, priv->port, - priv->user, priv->ghost, - priv->gport, priv->unixsock)) < 0) - return -1; - } else if (priv->unixsock && fd == -1) { - virt_viewer_app_trace(self, "Opening direct UNIX connection to display at %s", - priv->unixsock); - if ((fd = virt_viewer_app_open_unix_sock(priv->unixsock)) < 0) - return -1; - } + if (priv->transport && + g_ascii_strcasecmp(priv->transport, "ssh") == 0 && + !priv->direct && + fd == -1) { + gchar *p = NULL; + + if (priv->gport) { + virt_viewer_app_trace(self, "Opening indirect TCP connection to display at %s:%s\n", + priv->ghost, priv->gport); + } else { + virt_viewer_app_trace(self, "Opening indirect UNIX connection to display at %s\n", + priv->unixsock); + } + if (priv->port) + p = g_strdup_printf(":%d", priv->port); + + virt_viewer_app_trace(self, "Setting up SSH tunnel via %s%s%s%s\n", + priv->user ? priv->user : "", + priv->user ? "@" : "", + priv->host, p ? p : ""); + g_free(p); + + if ((fd = virt_viewer_app_open_tunnel_ssh(priv->host, priv->port, + priv->user, priv->ghost, + priv->gport, priv->unixsock)) < 0) + return -1; + } else if (priv->unixsock && fd == -1) { + virt_viewer_app_trace(self, "Opening direct UNIX connection to display at %s", + priv->unixsock); + if ((fd = virt_viewer_app_open_unix_sock(priv->unixsock)) < 0) + return -1; + } #endif - if (fd >= 0) { - return virt_viewer_session_open_fd(VIRT_VIEWER_SESSION(priv->session), fd); - } else if (priv->guri) { - virt_viewer_app_trace(self, "Opening connection to display at %s\n", priv->guri); - return virt_viewer_session_open_uri(VIRT_VIEWER_SESSION(priv->session), priv->guri); - } else { - virt_viewer_app_trace(self, "Opening direct TCP connection to display at %s:%s\n", - priv->ghost, priv->gport); - return virt_viewer_session_open_host(VIRT_VIEWER_SESSION(priv->session), - priv->ghost, priv->gport); - } + if (fd >= 0) { + return virt_viewer_session_open_fd(VIRT_VIEWER_SESSION(priv->session), fd); + } else if (priv->guri) { + virt_viewer_app_trace(self, "Opening connection to display at %s\n", priv->guri); + return virt_viewer_session_open_uri(VIRT_VIEWER_SESSION(priv->session), priv->guri); + } else { + virt_viewer_app_trace(self, "Opening direct TCP connection to display at %s:%s\n", + priv->ghost, priv->gport); + return virt_viewer_session_open_host(VIRT_VIEWER_SESSION(priv->session), + priv->ghost, priv->gport); + } - return -1; + return -1; } int virt_viewer_app_activate(VirtViewerApp *self) { - VirtViewerAppPrivate *priv; - int ret; + VirtViewerAppPrivate *priv; + int ret; - g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), -1); + g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), -1); - priv = self->priv; - if (priv->active) - return -1; + priv = self->priv; + if (priv->active) + return -1; - ret = VIRT_VIEWER_APP_GET_CLASS(self)->activate(self); + ret = VIRT_VIEWER_APP_GET_CLASS(self)->activate(self); - if (ret != -1) { - virt_viewer_app_show_status(self, _("Connecting to graphic server")); - priv->connected = FALSE; - priv->cancelled = FALSE; - priv->active = TRUE; - priv->grabbed = FALSE; - virt_viewer_app_update_title(self); - } + if (ret != -1) { + virt_viewer_app_show_status(self, _("Connecting to graphic server")); + priv->connected = FALSE; + priv->cancelled = FALSE; + priv->active = TRUE; + priv->grabbed = FALSE; + virt_viewer_app_update_title(self); + } - return ret; + return ret; } /* text was actually requested */ static void virt_viewer_app_clipboard_copy(GtkClipboard *clipboard G_GNUC_UNUSED, - GtkSelectionData *data, - guint info G_GNUC_UNUSED, - VirtViewerApp *self) + GtkSelectionData *data, + guint info G_GNUC_UNUSED, + VirtViewerApp *self) { - VirtViewerAppPrivate *priv = self->priv; + VirtViewerAppPrivate *priv = self->priv; - gtk_selection_data_set_text(data, priv->clipboard, -1); + gtk_selection_data_set_text(data, priv->clipboard, -1); } static void virt_viewer_app_server_cut_text(VirtViewerSession *session G_GNUC_UNUSED, - const gchar *text, - VirtViewerApp *self) + const gchar *text, + VirtViewerApp *self) { - GtkClipboard *cb; - gsize a, b; - VirtViewerAppPrivate *priv = self->priv; - GtkTargetEntry targets[] = { - {g_strdup("UTF8_STRING"), 0, 0}, - {g_strdup("COMPOUND_TEXT"), 0, 0}, - {g_strdup("TEXT"), 0, 0}, - {g_strdup("STRING"), 0, 0}, - }; + GtkClipboard *cb; + gsize a, b; + VirtViewerAppPrivate *priv = self->priv; + GtkTargetEntry targets[] = { + {g_strdup("UTF8_STRING"), 0, 0}, + {g_strdup("COMPOUND_TEXT"), 0, 0}, + {g_strdup("TEXT"), 0, 0}, + {g_strdup("STRING"), 0, 0}, + }; - if (!text) - return; + if (!text) + return; - g_free (priv->clipboard); - priv->clipboard = g_convert (text, -1, "utf-8", "iso8859-1", &a, &b, NULL); + g_free (priv->clipboard); + priv->clipboard = g_convert (text, -1, "utf-8", "iso8859-1", &a, &b, NULL); - if (priv->clipboard) { - cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); + if (priv->clipboard) { + cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); - gtk_clipboard_set_with_owner (cb, - targets, - G_N_ELEMENTS(targets), - (GtkClipboardGetFunc)virt_viewer_app_clipboard_copy, - NULL, - G_OBJECT (self)); - } + gtk_clipboard_set_with_owner (cb, + targets, + G_N_ELEMENTS(targets), + (GtkClipboardGetFunc)virt_viewer_app_clipboard_copy, + NULL, + G_OBJECT (self)); + } } static void virt_viewer_app_bell(VirtViewerSession *session G_GNUC_UNUSED, - VirtViewerApp *self) + VirtViewerApp *self) { - VirtViewerAppPrivate *priv = self->priv; + VirtViewerAppPrivate *priv = self->priv; - gdk_window_beep(gtk_widget_get_window(GTK_WIDGET(virt_viewer_window_get_window(priv->main_window)))); + gdk_window_beep(gtk_widget_get_window(GTK_WIDGET(virt_viewer_window_get_window(priv->main_window)))); } static int virt_viewer_app_default_initial_connect(VirtViewerApp *self) { - return virt_viewer_app_activate(self); + return virt_viewer_app_activate(self); } int virt_viewer_app_initial_connect(VirtViewerApp *self) { - VirtViewerAppClass *klass; + VirtViewerAppClass *klass; - g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), -1); - klass = VIRT_VIEWER_APP_GET_CLASS(self); + g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), -1); + klass = VIRT_VIEWER_APP_GET_CLASS(self); - return klass->initial_connect(self); + return klass->initial_connect(self); } static gboolean virt_viewer_app_retryauth(gpointer opaque) { - VirtViewerApp *self = opaque; + VirtViewerApp *self = opaque; - virt_viewer_app_initial_connect(self); + virt_viewer_app_initial_connect(self); - return FALSE; + return FALSE; } static gboolean virt_viewer_app_connect_timer(void *opaque) { - VirtViewerApp *self = opaque; - VirtViewerAppPrivate *priv = self->priv; + VirtViewerApp *self = opaque; + VirtViewerAppPrivate *priv = self->priv; - DEBUG_LOG("Connect timer fired"); + DEBUG_LOG("Connect timer fired"); - if (!priv->active && - virt_viewer_app_initial_connect(self) < 0) - gtk_main_quit(); + if (!priv->active && + virt_viewer_app_initial_connect(self) < 0) + gtk_main_quit(); - if (priv->active) { - priv->reconnect_poll = 0; - return FALSE; - } + if (priv->active) { + priv->reconnect_poll = 0; + return FALSE; + } - return TRUE; + return TRUE; } void virt_viewer_app_start_reconnect_poll(VirtViewerApp *self) { - g_return_if_fail(VIRT_VIEWER_IS_APP(self)); - VirtViewerAppPrivate *priv = self->priv; + g_return_if_fail(VIRT_VIEWER_IS_APP(self)); + VirtViewerAppPrivate *priv = self->priv; - if (priv->reconnect_poll != 0) - return; + if (priv->reconnect_poll != 0) + return; - priv->reconnect_poll = g_timeout_add(500, virt_viewer_app_connect_timer, self); + priv->reconnect_poll = g_timeout_add(500, virt_viewer_app_connect_timer, self); } static void virt_viewer_app_default_deactivated(VirtViewerApp *self) { - VirtViewerAppPrivate *priv = self->priv; + VirtViewerAppPrivate *priv = self->priv; - virt_viewer_app_show_status(self, _("Guest domain has shutdown")); - virt_viewer_app_trace(self, "Guest %s display has disconnected, shutting down", - priv->guest_name); - gtk_main_quit(); + virt_viewer_app_show_status(self, _("Guest domain has shutdown")); + virt_viewer_app_trace(self, "Guest %s display has disconnected, shutting down", + priv->guest_name); + gtk_main_quit(); } static void virt_viewer_app_deactivated(VirtViewerApp *self) { - VirtViewerAppClass *klass; - klass = VIRT_VIEWER_APP_GET_CLASS(self); + VirtViewerAppClass *klass; + klass = VIRT_VIEWER_APP_GET_CLASS(self); - klass->deactivated(self); + klass->deactivated(self); } static void virt_viewer_app_deactivate(VirtViewerApp *self) { - VirtViewerAppPrivate *priv = self->priv; + VirtViewerAppPrivate *priv = self->priv; - if (!priv->active) - return; + if (!priv->active) + return; - if (priv->session) - virt_viewer_session_close(VIRT_VIEWER_SESSION(priv->session)); + if (priv->session) + virt_viewer_session_close(VIRT_VIEWER_SESSION(priv->session)); - priv->connected = FALSE; - priv->active = FALSE; + priv->connected = FALSE; + priv->active = FALSE; #if 0 - g_free(priv->pretty_address); - priv->pretty_address = NULL; + g_free(priv->pretty_address); + priv->pretty_address = NULL; #endif - priv->grabbed = FALSE; - virt_viewer_app_update_title(self); + priv->grabbed = FALSE; + virt_viewer_app_update_title(self); - if (priv->authretry) { - priv->authretry = FALSE; - g_idle_add(virt_viewer_app_retryauth, self); - } else - virt_viewer_app_deactivated(self); + if (priv->authretry) { + priv->authretry = FALSE; + g_idle_add(virt_viewer_app_retryauth, self); + } else + virt_viewer_app_deactivated(self); } static void virt_viewer_app_connected(VirtViewerSession *session G_GNUC_UNUSED, - VirtViewerApp *self) + VirtViewerApp *self) { - VirtViewerAppPrivate *priv = self->priv; + VirtViewerAppPrivate *priv = self->priv; - priv->connected = TRUE; - virt_viewer_app_show_status(self, _("Connected to graphic server")); + priv->connected = TRUE; + virt_viewer_app_show_status(self, _("Connected to graphic server")); } static void virt_viewer_app_initialized(VirtViewerSession *session G_GNUC_UNUSED, - VirtViewerApp *self) + VirtViewerApp *self) { - gboolean has_usb = virt_viewer_session_has_usb(self->priv->session); + gboolean has_usb = virt_viewer_session_has_usb(self->priv->session); - virt_viewer_app_update_title(self); - virt_viewer_app_set_usb_options_sensitive(self, has_usb); + virt_viewer_app_update_title(self); + virt_viewer_app_set_usb_options_sensitive(self, has_usb); } static void virt_viewer_app_disconnected(VirtViewerSession *session G_GNUC_UNUSED, - VirtViewerApp *self) + VirtViewerApp *self) { - VirtViewerAppPrivate *priv = self->priv; + VirtViewerAppPrivate *priv = self->priv; - if (!priv->connected && !priv->cancelled) { - virt_viewer_app_simple_message_dialog(self, - _("Unable to connect to the graphic server %s"), - priv->pretty_address); - } - virt_viewer_app_set_usb_options_sensitive(self, FALSE); - virt_viewer_app_deactivate(self); + if (!priv->connected && !priv->cancelled) { + virt_viewer_app_simple_message_dialog(self, + _("Unable to connect to the graphic server %s"), + priv->pretty_address); + } + virt_viewer_app_set_usb_options_sensitive(self, FALSE); + virt_viewer_app_deactivate(self); } static void virt_viewer_app_cancelled(VirtViewerSession *session, - VirtViewerApp *self) + VirtViewerApp *self) { - VirtViewerAppPrivate *priv = self->priv; - priv->cancelled = TRUE; - virt_viewer_app_disconnected(session, self); + VirtViewerAppPrivate *priv = self->priv; + priv->cancelled = TRUE; + virt_viewer_app_disconnected(session, self); } static void virt_viewer_app_auth_refused(VirtViewerSession *session G_GNUC_UNUSED, - const char *msg, - VirtViewerApp *self) + const char *msg, + VirtViewerApp *self) { - GtkWidget *dialog; - int ret; - VirtViewerAppPrivate *priv = self->priv; + GtkWidget *dialog; + int ret; + VirtViewerAppPrivate *priv = self->priv; - dialog = gtk_message_dialog_new(virt_viewer_window_get_window(priv->main_window), - GTK_DIALOG_MODAL | - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_YES_NO, - _("Unable to authenticate with remote desktop server at %s: %s\n" - "Retry connection again?"), - priv->pretty_address, msg); + dialog = gtk_message_dialog_new(virt_viewer_window_get_window(priv->main_window), + GTK_DIALOG_MODAL | + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_YES_NO, + _("Unable to authenticate with remote desktop server at %s: %s\n" + "Retry connection again?"), + priv->pretty_address, msg); - ret = gtk_dialog_run(GTK_DIALOG(dialog)); + ret = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); + gtk_widget_destroy(dialog); - if (ret == GTK_RESPONSE_YES) - priv->authretry = TRUE; - else - priv->authretry = FALSE; + if (ret == GTK_RESPONSE_YES) + priv->authretry = TRUE; + else + priv->authretry = FALSE; } static void virt_viewer_app_auth_failed(VirtViewerSession *session G_GNUC_UNUSED, - const char *msg, - VirtViewerApp *self) + const char *msg, + VirtViewerApp *self) { - virt_viewer_app_simple_message_dialog(self, - _("Unable to authenticate with remote desktop server: %s"), - msg); + virt_viewer_app_simple_message_dialog(self, + _("Unable to authenticate with remote desktop server: %s"), + msg); } static void virt_viewer_app_usb_failed(VirtViewerSession *session G_GNUC_UNUSED, - const gchar *msg, - VirtViewerApp *self) + const gchar *msg, + VirtViewerApp *self) { - virt_viewer_app_simple_message_dialog(self, _("USB redirection error: %s"), msg); + virt_viewer_app_simple_message_dialog(self, _("USB redirection error: %s"), msg); } static void virt_viewer_app_get_property (GObject *object, guint property_id, - GValue *value G_GNUC_UNUSED, GParamSpec *pspec) + GValue *value G_GNUC_UNUSED, GParamSpec *pspec) { - g_return_if_fail(VIRT_VIEWER_IS_APP(object)); - VirtViewerApp *self = VIRT_VIEWER_APP(object); - VirtViewerAppPrivate *priv = self->priv; + g_return_if_fail(VIRT_VIEWER_IS_APP(object)); + VirtViewerApp *self = VIRT_VIEWER_APP(object); + VirtViewerAppPrivate *priv = self->priv; - switch (property_id) { - case PROP_VERBOSE: - g_value_set_boolean(value, priv->verbose); - break; + switch (property_id) { + case PROP_VERBOSE: + g_value_set_boolean(value, priv->verbose); + break; - case PROP_CONTAINER: - g_value_set_object(value, priv->container); - break; + case PROP_CONTAINER: + g_value_set_object(value, priv->container); + break; - case PROP_SESSION: - g_value_set_object(value, priv->session); - break; + case PROP_SESSION: + g_value_set_object(value, priv->session); + break; - case PROP_GUEST_NAME: - g_value_set_string(value, priv->guest_name); - break; + case PROP_GUEST_NAME: + g_value_set_string(value, priv->guest_name); + break; - case PROP_GURI: - g_value_set_string(value, priv->guri); - break; + case PROP_GURI: + g_value_set_string(value, priv->guri); + break; - case PROP_FULLSCREEN: - g_value_set_boolean(value, priv->fullscreen); - break; + case PROP_FULLSCREEN: + g_value_set_boolean(value, priv->fullscreen); + break; - case PROP_TITLE: - g_value_set_string(value, priv->title); - break; + case PROP_TITLE: + g_value_set_string(value, priv->title); + break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } } static void virt_viewer_app_set_property (GObject *object, guint property_id, - const GValue *value G_GNUC_UNUSED, GParamSpec *pspec) -{ - g_return_if_fail(VIRT_VIEWER_IS_APP(object)); - VirtViewerApp *self = VIRT_VIEWER_APP(object); - VirtViewerAppPrivate *priv = self->priv; - - switch (property_id) { - case PROP_VERBOSE: - priv->verbose = g_value_get_boolean(value); - break; - - case PROP_CONTAINER: - g_return_if_fail(priv->container == NULL); - priv->container = g_value_dup_object(value); - break; - - case PROP_GUEST_NAME: - g_free(priv->guest_name); - priv->guest_name = g_value_dup_string(value); - break; - - case PROP_GURI: - g_free(priv->guri); - priv->guri = g_value_dup_string(value); - virt_viewer_app_update_pretty_address(self); - break; - - case PROP_FULLSCREEN: - virt_viewer_app_set_fullscreen(self, g_value_get_boolean(value)); - break; - - case PROP_TITLE: - g_free(priv->title); - priv->title = g_value_dup_string(value); - virt_viewer_app_set_all_window_subtitles(self); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } + const GValue *value G_GNUC_UNUSED, GParamSpec *pspec) +{ + g_return_if_fail(VIRT_VIEWER_IS_APP(object)); + VirtViewerApp *self = VIRT_VIEWER_APP(object); + VirtViewerAppPrivate *priv = self->priv; + + switch (property_id) { + case PROP_VERBOSE: + priv->verbose = g_value_get_boolean(value); + break; + + case PROP_CONTAINER: + g_return_if_fail(priv->container == NULL); + priv->container = g_value_dup_object(value); + break; + + case PROP_GUEST_NAME: + g_free(priv->guest_name); + priv->guest_name = g_value_dup_string(value); + break; + + case PROP_GURI: + g_free(priv->guri); + priv->guri = g_value_dup_string(value); + virt_viewer_app_update_pretty_address(self); + break; + + case PROP_FULLSCREEN: + virt_viewer_app_set_fullscreen(self, g_value_get_boolean(value)); + break; + + case PROP_TITLE: + g_free(priv->title); + priv->title = g_value_dup_string(value); + virt_viewer_app_set_all_window_subtitles(self); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } } static void virt_viewer_app_dispose (GObject *object) { - VirtViewerApp *self = VIRT_VIEWER_APP(object); - VirtViewerAppPrivate *priv = self->priv; + VirtViewerApp *self = VIRT_VIEWER_APP(object); + VirtViewerAppPrivate *priv = self->priv; - if (priv->windows) { - g_hash_table_unref(priv->windows); - priv->windows = NULL; - } + if (priv->windows) { + g_hash_table_unref(priv->windows); + priv->windows = NULL; + } - if (priv->main_window) { - g_object_unref(priv->main_window); - priv->main_window = NULL; - } + if (priv->main_window) { + g_object_unref(priv->main_window); + priv->main_window = NULL; + } - if (priv->container) { - g_object_unref(priv->container); - priv->container = NULL; - } - g_free(priv->title); + if (priv->container) { + g_object_unref(priv->container); + priv->container = NULL; + } + g_free(priv->title); - virt_viewer_app_free_connect_info(self); + virt_viewer_app_free_connect_info(self); - G_OBJECT_CLASS (virt_viewer_app_parent_class)->dispose (object); + G_OBJECT_CLASS (virt_viewer_app_parent_class)->dispose (object); } static gboolean virt_viewer_app_default_start(VirtViewerApp *self) { - VirtViewerAppPrivate *priv; - GtkWindow *win; - priv = self->priv; + VirtViewerAppPrivate *priv; + GtkWindow *win; + priv = self->priv; - win = virt_viewer_window_get_window(priv->main_window); - if (win) - gtk_widget_show(GTK_WIDGET(win)); - else { - gtk_box_pack_end(GTK_BOX(priv->container), priv->main_notebook, TRUE, TRUE, 0); - gtk_widget_show(GTK_WIDGET(priv->main_notebook)); - } + win = virt_viewer_window_get_window(priv->main_window); + if (win) + gtk_widget_show(GTK_WIDGET(win)); + else { + gtk_box_pack_end(GTK_BOX(priv->container), priv->main_notebook, TRUE, TRUE, 0); + gtk_widget_show(GTK_WIDGET(priv->main_notebook)); + } - return TRUE; + return TRUE; } gboolean virt_viewer_app_start(VirtViewerApp *self) { - VirtViewerAppClass *klass; + VirtViewerAppClass *klass; - g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), FALSE); - klass = VIRT_VIEWER_APP_GET_CLASS(self); + g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), FALSE); + klass = VIRT_VIEWER_APP_GET_CLASS(self); - g_return_val_if_fail(!self->priv->started, TRUE); + g_return_val_if_fail(!self->priv->started, TRUE); - self->priv->started = klass->start(self); - return self->priv->started; + self->priv->started = klass->start(self); + return self->priv->started; } static void virt_viewer_app_init (VirtViewerApp *self) { - self->priv = GET_PRIVATE(self); - self->priv->windows = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_object_unref); + self->priv = GET_PRIVATE(self); + self->priv->windows = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_object_unref); } static GObject * virt_viewer_app_constructor (GType gtype, - guint n_properties, - GObjectConstructParam *properties) + guint n_properties, + GObjectConstructParam *properties) { - GObject *obj; - VirtViewerApp *self; - VirtViewerAppPrivate *priv; + GObject *obj; + VirtViewerApp *self; + VirtViewerAppPrivate *priv; - obj = G_OBJECT_CLASS (virt_viewer_app_parent_class)->constructor (gtype, n_properties, properties); - self = VIRT_VIEWER_APP(obj); - priv = self->priv; + obj = G_OBJECT_CLASS (virt_viewer_app_parent_class)->constructor (gtype, n_properties, properties); + self = VIRT_VIEWER_APP(obj); + priv = self->priv; - priv->main_window = virt_viewer_app_window_new(self, priv->container, 0); - priv->main_notebook = GTK_WIDGET(virt_viewer_window_get_notebook(priv->main_window)); + priv->main_window = virt_viewer_app_window_new(self, priv->container, 0); + priv->main_notebook = GTK_WIDGET(virt_viewer_window_get_notebook(priv->main_window)); - return obj; + return obj; } static void virt_viewer_app_class_init (VirtViewerAppClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (VirtViewerAppPrivate)); - - object_class->constructor = virt_viewer_app_constructor; - object_class->get_property = virt_viewer_app_get_property; - object_class->set_property = virt_viewer_app_set_property; - object_class->dispose = virt_viewer_app_dispose; - - klass->start = virt_viewer_app_default_start; - klass->initial_connect = virt_viewer_app_default_initial_connect; - klass->activate = virt_viewer_app_default_activate; - klass->deactivated = virt_viewer_app_default_deactivated; - klass->open_connection = virt_viewer_app_default_open_connection; - - g_object_class_install_property(object_class, - PROP_VERBOSE, - g_param_spec_boolean("verbose", - "Verbose", - "Verbose trace", - FALSE, - G_PARAM_READABLE | - G_PARAM_WRITABLE | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property(object_class, - PROP_CONTAINER, - g_param_spec_object("container", - "Container", - "Widget container", - GTK_TYPE_WIDGET, - G_PARAM_READABLE | - G_PARAM_WRITABLE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property(object_class, - PROP_SESSION, - g_param_spec_object("session", - "Session", - "ViewerSession", - VIRT_VIEWER_TYPE_SESSION, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property(object_class, - PROP_GUEST_NAME, - g_param_spec_string("guest-name", - "Guest name", - "Guest name", - "", - G_PARAM_READABLE | - G_PARAM_WRITABLE | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property(object_class, - PROP_GURI, - g_param_spec_string("guri", - "guri", - "Remote graphical URI", - "", - G_PARAM_READABLE | - G_PARAM_WRITABLE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property(object_class, - PROP_FULLSCREEN, - g_param_spec_boolean("fullscreen", - "Fullscreen", - "Fullscreen", - FALSE, - G_PARAM_READABLE | - G_PARAM_WRITABLE | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property(object_class, - PROP_TITLE, - g_param_spec_string("title", - "Title", - "Title", - "", - G_PARAM_READABLE | - G_PARAM_WRITABLE | - G_PARAM_STATIC_STRINGS)); - - signals[SIGNAL_WINDOW_ADDED] = - g_signal_new("window-added", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(VirtViewerAppClass, window_added), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, - 1, - G_TYPE_OBJECT); - - signals[SIGNAL_WINDOW_REMOVED] = - g_signal_new("window-removed", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(VirtViewerAppClass, window_removed), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, - 1, - G_TYPE_OBJECT); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (VirtViewerAppPrivate)); + + object_class->constructor = virt_viewer_app_constructor; + object_class->get_property = virt_viewer_app_get_property; + object_class->set_property = virt_viewer_app_set_property; + object_class->dispose = virt_viewer_app_dispose; + + klass->start = virt_viewer_app_default_start; + klass->initial_connect = virt_viewer_app_default_initial_connect; + klass->activate = virt_viewer_app_default_activate; + klass->deactivated = virt_viewer_app_default_deactivated; + klass->open_connection = virt_viewer_app_default_open_connection; + + g_object_class_install_property(object_class, + PROP_VERBOSE, + g_param_spec_boolean("verbose", + "Verbose", + "Verbose trace", + FALSE, + G_PARAM_READABLE | + G_PARAM_WRITABLE | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property(object_class, + PROP_CONTAINER, + g_param_spec_object("container", + "Container", + "Widget container", + GTK_TYPE_WIDGET, + G_PARAM_READABLE | + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property(object_class, + PROP_SESSION, + g_param_spec_object("session", + "Session", + "ViewerSession", + VIRT_VIEWER_TYPE_SESSION, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property(object_class, + PROP_GUEST_NAME, + g_param_spec_string("guest-name", + "Guest name", + "Guest name", + "", + G_PARAM_READABLE | + G_PARAM_WRITABLE | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property(object_class, + PROP_GURI, + g_param_spec_string("guri", + "guri", + "Remote graphical URI", + "", + G_PARAM_READABLE | + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property(object_class, + PROP_FULLSCREEN, + g_param_spec_boolean("fullscreen", + "Fullscreen", + "Fullscreen", + FALSE, + G_PARAM_READABLE | + G_PARAM_WRITABLE | + G_PARAM_STATIC_STRINGS)); + g_object_class_install_property(object_class, + PROP_TITLE, + g_param_spec_string("title", + "Title", + "Title", + "", + G_PARAM_READABLE | + G_PARAM_WRITABLE | + G_PARAM_STATIC_STRINGS)); + + signals[SIGNAL_WINDOW_ADDED] = + g_signal_new("window-added", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(VirtViewerAppClass, window_added), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, + 1, + G_TYPE_OBJECT); + + signals[SIGNAL_WINDOW_REMOVED] = + g_signal_new("window-removed", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(VirtViewerAppClass, window_removed), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, + 1, + G_TYPE_OBJECT); } void virt_viewer_app_set_direct(VirtViewerApp *self, gboolean direct) { - g_return_if_fail(VIRT_VIEWER_IS_APP(self)); + g_return_if_fail(VIRT_VIEWER_IS_APP(self)); - self->priv->direct = direct; + self->priv->direct = direct; } void virt_viewer_app_set_attach(VirtViewerApp *self, gboolean attach) { - g_return_if_fail(VIRT_VIEWER_IS_APP(self)); + g_return_if_fail(VIRT_VIEWER_IS_APP(self)); - self->priv->attach = attach; + self->priv->attach = attach; } gboolean virt_viewer_app_get_attach(VirtViewerApp *self) { - g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), FALSE); + g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), FALSE); - return self->priv->attach; + return self->priv->attach; } gboolean virt_viewer_app_is_active(VirtViewerApp *self) { - g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), FALSE); + g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), FALSE); - return self->priv->active; + return self->priv->active; } gboolean virt_viewer_app_has_session(VirtViewerApp *self) { - g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), FALSE); + g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), FALSE); - return self->priv->session != NULL; + return self->priv->session != NULL; } static void virt_viewer_app_update_pretty_address(VirtViewerApp *self) { - VirtViewerAppPrivate *priv; + VirtViewerAppPrivate *priv; - priv = self->priv; - g_free(priv->pretty_address); - if (priv->guri) - priv->pretty_address = g_strdup(priv->guri); - else if (priv->gport) - priv->pretty_address = g_strdup_printf("%s:%s", priv->ghost, priv->gport); - else - priv->pretty_address = g_strdup_printf("%s:%s", priv->host, priv->unixsock); + priv = self->priv; + g_free(priv->pretty_address); + if (priv->guri) + priv->pretty_address = g_strdup(priv->guri); + else if (priv->gport) + priv->pretty_address = g_strdup_printf("%s:%s", priv->ghost, priv->gport); + else + priv->pretty_address = g_strdup_printf("%s:%s", priv->host, priv->unixsock); } typedef struct { - gboolean fullscreen; - gboolean move; + gboolean fullscreen; + gboolean move; } FullscreenOptions; static void fullscreen_cb(gpointer key, - gpointer value, - gpointer user_data) + gpointer value, + gpointer user_data) { - gint nth = *(gint*)key; - FullscreenOptions *options = (FullscreenOptions *)user_data; - VirtViewerWindow *vwin = VIRT_VIEWER_WINDOW(value); + gint nth = *(gint*)key; + FullscreenOptions *options = (FullscreenOptions *)user_data; + VirtViewerWindow *vwin = VIRT_VIEWER_WINDOW(value); - DEBUG_LOG("fullscreen display %d: %d", nth, options->fullscreen); - if (options->fullscreen) { - GdkScreen *screen = gdk_screen_get_default (); - GdkRectangle mon; + DEBUG_LOG("fullscreen display %d: %d", nth, options->fullscreen); + if (options->fullscreen) { + GdkScreen *screen = gdk_screen_get_default (); + GdkRectangle mon; - if (nth >= gdk_screen_get_n_monitors(screen)) { - DEBUG_LOG("skipping display %d", nth); - return; - } - gdk_screen_get_monitor_geometry(screen, nth, &mon); - virt_viewer_window_enter_fullscreen(vwin, options->move, mon.x, mon.y); - } else - virt_viewer_window_leave_fullscreen(vwin); + if (nth >= gdk_screen_get_n_monitors(screen)) { + DEBUG_LOG("skipping display %d", nth); + return; + } + gdk_screen_get_monitor_geometry(screen, nth, &mon); + virt_viewer_window_enter_fullscreen(vwin, options->move, mon.x, mon.y); + } else + virt_viewer_window_leave_fullscreen(vwin); } static void virt_viewer_app_set_fullscreen(VirtViewerApp *self, gboolean fullscreen) { - VirtViewerAppPrivate *priv = self->priv; - FullscreenOptions options = { - .fullscreen = fullscreen, - .move = virt_viewer_app_get_n_windows_visible(self) > 1, - }; + VirtViewerAppPrivate *priv = self->priv; + FullscreenOptions options = { + .fullscreen = fullscreen, + .move = virt_viewer_app_get_n_windows_visible(self) > 1, + }; - /* we iterate unconditionnaly, even if it was set before to update new windows */ - priv->fullscreen = fullscreen; - g_hash_table_foreach(priv->windows, fullscreen_cb, &options); + /* we iterate unconditionnaly, even if it was set before to update new windows */ + priv->fullscreen = fullscreen; + g_hash_table_foreach(priv->windows, fullscreen_cb, &options); } static void menu_display_visible_toggled_cb(GtkCheckMenuItem *checkmenuitem, - VirtViewerWindow *vwin) + VirtViewerWindow *vwin) { - VirtViewerApp *self; - gboolean visible; - static gboolean reentering = FALSE; + VirtViewerApp *self; + gboolean visible; + static gboolean reentering = FALSE; - if (reentering) /* do not reenter if I switch you back */ - return; + if (reentering) /* do not reenter if I switch you back */ + return; - reentering = TRUE; - g_object_get(vwin, "app", &self, NULL); - visible = virt_viewer_app_window_set_visible(self, vwin, - gtk_check_menu_item_get_active(checkmenuitem)); - gtk_check_menu_item_set_active(checkmenuitem, /* will be toggled again */ !visible); - g_object_unref(self); - reentering = FALSE; + reentering = TRUE; + g_object_get(vwin, "app", &self, NULL); + visible = virt_viewer_app_window_set_visible(self, vwin, + gtk_check_menu_item_get_active(checkmenuitem)); + gtk_check_menu_item_set_active(checkmenuitem, /* will be toggled again */ !visible); + g_object_unref(self); + reentering = FALSE; } static gint update_menu_displays_sort(gconstpointer a, gconstpointer b) { - const int *ai = a; - const int *bi = b; + const int *ai = a; + const int *bi = b; - if (*ai > *bi) - return 1; - else if (*ai < *bi) - return -1; - else - return 0; + if (*ai > *bi) + return 1; + else if (*ai < *bi) + return -1; + else + return 0; } static void window_update_menu_displays_cb(gpointer key G_GNUC_UNUSED, - gpointer value, - gpointer user_data) -{ - VirtViewerApp *self = VIRT_VIEWER_APP(user_data); - VirtViewerWindow *window = VIRT_VIEWER_WINDOW(value); - GtkMenuShell *submenu = GTK_MENU_SHELL(gtk_menu_new()); - GtkMenuItem *menu = virt_viewer_window_get_menu_displays(window); - GList *keys = g_hash_table_get_keys(self->priv->windows); - GList *tmp; - - keys = g_list_sort(keys, update_menu_displays_sort); - - tmp = keys; - while (tmp) { - int *nth = tmp->data; - VirtViewerWindow *vwin = VIRT_VIEWER_WINDOW(g_hash_table_lookup(self->priv->windows, nth)); - GtkWidget *item; - gboolean visible; - - item = gtk_check_menu_item_new_with_label(g_strdup_printf("Display %d", *nth)); - visible = gtk_widget_get_visible(GTK_WIDGET(virt_viewer_window_get_window(vwin))); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), visible); - g_signal_connect(G_OBJECT(item), - "toggled", G_CALLBACK(menu_display_visible_toggled_cb), vwin); - gtk_menu_shell_append(submenu, item); - tmp = tmp->next; - } - - gtk_widget_show_all(GTK_WIDGET(submenu)); - gtk_menu_item_set_submenu(menu, GTK_WIDGET(submenu)); - g_list_free(keys); + gpointer value, + gpointer user_data) +{ + VirtViewerApp *self = VIRT_VIEWER_APP(user_data); + VirtViewerWindow *window = VIRT_VIEWER_WINDOW(value); + GtkMenuShell *submenu = GTK_MENU_SHELL(gtk_menu_new()); + GtkMenuItem *menu = virt_viewer_window_get_menu_displays(window); + GList *keys = g_hash_table_get_keys(self->priv->windows); + GList *tmp; + + keys = g_list_sort(keys, update_menu_displays_sort); + + tmp = keys; + while (tmp) { + int *nth = tmp->data; + VirtViewerWindow *vwin = VIRT_VIEWER_WINDOW(g_hash_table_lookup(self->priv->windows, nth)); + GtkWidget *item; + gboolean visible; + + item = gtk_check_menu_item_new_with_label(g_strdup_printf("Display %d", *nth)); + visible = gtk_widget_get_visible(GTK_WIDGET(virt_viewer_window_get_window(vwin))); + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), visible); + g_signal_connect(G_OBJECT(item), + "toggled", G_CALLBACK(menu_display_visible_toggled_cb), vwin); + gtk_menu_shell_append(submenu, item); + tmp = tmp->next; + } + + gtk_widget_show_all(GTK_WIDGET(submenu)); + gtk_menu_item_set_submenu(menu, GTK_WIDGET(submenu)); + g_list_free(keys); } static void virt_viewer_app_update_menu_displays(VirtViewerApp *self) { - g_hash_table_foreach(self->priv->windows, window_update_menu_displays_cb, self); + g_hash_table_foreach(self->priv->windows, window_update_menu_displays_cb, self); } void virt_viewer_app_set_connect_info(VirtViewerApp *self, - const gchar *host, - const gchar *ghost, - const gchar *gport, - const gchar *transport, - const gchar *unixsock, - const gchar *user, - gint port, - const gchar *guri) -{ - g_return_if_fail(VIRT_VIEWER_IS_APP(self)); - VirtViewerAppPrivate *priv = self->priv; - - DEBUG_LOG("Set connect info: %s,%s,%s,%s,%s,%s,%d", - host, ghost, gport, transport, unixsock, user, port); - - g_free(priv->host); - g_free(priv->ghost); - g_free(priv->gport); - g_free(priv->transport); - g_free(priv->unixsock); - g_free(priv->user); - g_free(priv->guri); - - priv->host = g_strdup(host); - priv->ghost = g_strdup(ghost); - priv->gport = g_strdup(gport); - priv->transport = g_strdup(transport); - priv->unixsock = g_strdup(unixsock); - priv->user = g_strdup(user); - priv->guri = g_strdup(guri); - priv->port = port; - - virt_viewer_app_update_pretty_address(self); + const gchar *host, + const gchar *ghost, + const gchar *gport, + const gchar *transport, + const gchar *unixsock, + const gchar *user, + gint port, + const gchar *guri) +{ + g_return_if_fail(VIRT_VIEWER_IS_APP(self)); + VirtViewerAppPrivate *priv = self->priv; + + DEBUG_LOG("Set connect info: %s,%s,%s,%s,%s,%s,%d", + host, ghost, gport, transport, unixsock, user, port); + + g_free(priv->host); + g_free(priv->ghost); + g_free(priv->gport); + g_free(priv->transport); + g_free(priv->unixsock); + g_free(priv->user); + g_free(priv->guri); + + priv->host = g_strdup(host); + priv->ghost = g_strdup(ghost); + priv->gport = g_strdup(gport); + priv->transport = g_strdup(transport); + priv->unixsock = g_strdup(unixsock); + priv->user = g_strdup(user); + priv->guri = g_strdup(guri); + priv->port = port; + + virt_viewer_app_update_pretty_address(self); } void virt_viewer_app_free_connect_info(VirtViewerApp *self) { - g_return_if_fail(VIRT_VIEWER_IS_APP(self)); + g_return_if_fail(VIRT_VIEWER_IS_APP(self)); - virt_viewer_app_set_connect_info(self, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL); + virt_viewer_app_set_connect_info(self, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL); } VirtViewerWindow* virt_viewer_app_get_main_window(VirtViewerApp *self) { - g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), NULL); + g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), NULL); - return self->priv->main_window; + return self->priv->main_window; } static void show_status_cb(gpointer key G_GNUC_UNUSED, - gpointer value, - gpointer user_data) + gpointer value, + gpointer user_data) { - VirtViewerNotebook *nb = virt_viewer_window_get_notebook(VIRT_VIEWER_WINDOW(value)); - gchar *text = (gchar*)user_data; + VirtViewerNotebook *nb = virt_viewer_window_get_notebook(VIRT_VIEWER_WINDOW(value)); + gchar *text = (gchar*)user_data; - virt_viewer_notebook_show_status(nb, text); + virt_viewer_notebook_show_status(nb, text); } void virt_viewer_app_show_status(VirtViewerApp *self, const gchar *fmt, ...) { - va_list args; - gchar *text; + va_list args; + gchar *text; - g_return_if_fail(VIRT_VIEWER_IS_APP(self)); - g_return_if_fail(fmt != NULL); + g_return_if_fail(VIRT_VIEWER_IS_APP(self)); + g_return_if_fail(fmt != NULL); - va_start(args, fmt); - text = g_strdup_vprintf(fmt, args); - va_end(args); + va_start(args, fmt); + text = g_strdup_vprintf(fmt, args); + va_end(args); - g_hash_table_foreach(self->priv->windows, show_status_cb, text); - g_free(text); + g_hash_table_foreach(self->priv->windows, show_status_cb, text); + g_free(text); } static void show_display_cb(gpointer key G_GNUC_UNUSED, - gpointer value, - gpointer user_data G_GNUC_UNUSED) + gpointer value, + gpointer user_data G_GNUC_UNUSED) { - VirtViewerNotebook *nb = virt_viewer_window_get_notebook(VIRT_VIEWER_WINDOW(value)); + VirtViewerNotebook *nb = virt_viewer_window_get_notebook(VIRT_VIEWER_WINDOW(value)); - virt_viewer_notebook_show_display(nb); + virt_viewer_notebook_show_display(nb); } void virt_viewer_app_show_display(VirtViewerApp *self) { - g_return_if_fail(VIRT_VIEWER_IS_APP(self)); - g_hash_table_foreach(self->priv->windows, show_display_cb, self); + g_return_if_fail(VIRT_VIEWER_IS_APP(self)); + g_hash_table_foreach(self->priv->windows, show_display_cb, self); } GHashTable* virt_viewer_app_get_windows(VirtViewerApp *self) { - g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), NULL); - return self->priv->windows; + g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), NULL); + return self->priv->windows; } void virt_viewer_app_usb_device_selection(VirtViewerApp *self, - GtkWindow *parent) + GtkWindow *parent) { - g_return_if_fail(VIRT_VIEWER_IS_APP(self)); - g_return_if_fail(self->priv->session != NULL); + g_return_if_fail(VIRT_VIEWER_IS_APP(self)); + g_return_if_fail(self->priv->session != NULL); - virt_viewer_session_usb_device_selection(self->priv->session, parent); + virt_viewer_session_usb_device_selection(self->priv->session, parent); } /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 - * indent-tabs-mode: t + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/virt-viewer-app.h b/src/virt-viewer-app.h index 3170dae..950b434 100644 --- a/src/virt-viewer-app.h +++ b/src/virt-viewer-app.h @@ -39,23 +39,23 @@ G_BEGIN_DECLS typedef struct _VirtViewerAppPrivate VirtViewerAppPrivate; typedef struct { - GObject parent; - VirtViewerAppPrivate *priv; + GObject parent; + VirtViewerAppPrivate *priv; } VirtViewerApp; typedef struct { - GObjectClass parent_class; + GObjectClass parent_class; - /* signals */ - void (*window_added) (VirtViewerApp *self, VirtViewerWindow *window); - void (*window_removed) (VirtViewerApp *self, VirtViewerWindow *window); + /* signals */ + void (*window_added) (VirtViewerApp *self, VirtViewerWindow *window); + void (*window_removed) (VirtViewerApp *self, VirtViewerWindow *window); - /*< private >*/ - gboolean (*start) (VirtViewerApp *self); - int (*initial_connect) (VirtViewerApp *self); - int (*activate) (VirtViewerApp *self); - void (*deactivated) (VirtViewerApp *self); - gboolean (*open_connection)(VirtViewerApp *self, int *fd); + /*< private >*/ + gboolean (*start) (VirtViewerApp *self); + int (*initial_connect) (VirtViewerApp *self); + int (*activate) (VirtViewerApp *self); + void (*deactivated) (VirtViewerApp *self); + gboolean (*open_connection)(VirtViewerApp *self, int *fd); } VirtViewerAppClass; GType virt_viewer_app_get_type (void); @@ -92,8 +92,15 @@ void virt_viewer_app_show_display(VirtViewerApp *self); GHashTable* virt_viewer_app_get_windows(VirtViewerApp *self); void virt_viewer_app_usb_device_selection(VirtViewerApp *self, - GtkWindow *parent); + GtkWindow *parent); G_END_DECLS #endif /* VIRT_VIEWER_APP_H */ +/* + * Local variables: + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/src/virt-viewer-auth.c b/src/virt-viewer-auth.c index 52eb4c9..9371d03 100644 --- a/src/virt-viewer-auth.c +++ b/src/virt-viewer-auth.c @@ -34,142 +34,142 @@ int virt_viewer_auth_collect_credentials(const char *type, - const char *address, - char **username, - char **password) + const char *address, + char **username, + char **password) { - GtkWidget *dialog = NULL; - GtkBuilder *creds = virt_viewer_util_load_ui("virt-viewer-auth.xml"); - GtkWidget *credUsername; - GtkWidget *credPassword; - GtkWidget *promptUsername; - GtkWidget *promptPassword; - GtkWidget *labelMessage; - int response; - char *message; - - dialog = GTK_WIDGET(gtk_builder_get_object(creds, "auth")); - gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); - - labelMessage = GTK_WIDGET(gtk_builder_get_object(creds, "message")); - credUsername = GTK_WIDGET(gtk_builder_get_object(creds, "cred-username")); - promptUsername = GTK_WIDGET(gtk_builder_get_object(creds, "prompt-username")); - credPassword = GTK_WIDGET(gtk_builder_get_object(creds, "cred-password")); - promptPassword = GTK_WIDGET(gtk_builder_get_object(creds, "prompt-password")); - - gtk_widget_set_sensitive(credUsername, username != NULL); - gtk_widget_set_sensitive(promptUsername, username != NULL); - gtk_widget_set_sensitive(credPassword, password != NULL); - gtk_widget_set_sensitive(promptPassword, password != NULL); - - if (address) { - message = g_strdup_printf("Authentication is required for the %s connection to:\n\n" - "<b>%s</b>\n\n", - type, - address); - } else { - message = g_strdup_printf("Authentication is required for the %s connection:\n", - type); - } - - gtk_label_set_markup(GTK_LABEL(labelMessage), message); - g_free(message); - - gtk_widget_show_all(dialog); - response = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_hide(dialog); - - if (response == GTK_RESPONSE_OK) { - if (username) - *username = g_strdup(gtk_entry_get_text(GTK_ENTRY(credUsername))); - if (password) - *password = g_strdup(gtk_entry_get_text(GTK_ENTRY(credPassword))); - } - - gtk_widget_destroy(GTK_WIDGET(dialog)); - - return response == GTK_RESPONSE_OK ? 0 : -1; + GtkWidget *dialog = NULL; + GtkBuilder *creds = virt_viewer_util_load_ui("virt-viewer-auth.xml"); + GtkWidget *credUsername; + GtkWidget *credPassword; + GtkWidget *promptUsername; + GtkWidget *promptPassword; + GtkWidget *labelMessage; + int response; + char *message; + + dialog = GTK_WIDGET(gtk_builder_get_object(creds, "auth")); + gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); + + labelMessage = GTK_WIDGET(gtk_builder_get_object(creds, "message")); + credUsername = GTK_WIDGET(gtk_builder_get_object(creds, "cred-username")); + promptUsername = GTK_WIDGET(gtk_builder_get_object(creds, "prompt-username")); + credPassword = GTK_WIDGET(gtk_builder_get_object(creds, "cred-password")); + promptPassword = GTK_WIDGET(gtk_builder_get_object(creds, "prompt-password")); + + gtk_widget_set_sensitive(credUsername, username != NULL); + gtk_widget_set_sensitive(promptUsername, username != NULL); + gtk_widget_set_sensitive(credPassword, password != NULL); + gtk_widget_set_sensitive(promptPassword, password != NULL); + + if (address) { + message = g_strdup_printf("Authentication is required for the %s connection to:\n\n" + "<b>%s</b>\n\n", + type, + address); + } else { + message = g_strdup_printf("Authentication is required for the %s connection:\n", + type); + } + + gtk_label_set_markup(GTK_LABEL(labelMessage), message); + g_free(message); + + gtk_widget_show_all(dialog); + response = gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_hide(dialog); + + if (response == GTK_RESPONSE_OK) { + if (username) + *username = g_strdup(gtk_entry_get_text(GTK_ENTRY(credUsername))); + if (password) + *password = g_strdup(gtk_entry_get_text(GTK_ENTRY(credPassword))); + } + + gtk_widget_destroy(GTK_WIDGET(dialog)); + + return response == GTK_RESPONSE_OK ? 0 : -1; } #ifdef HAVE_GTK_VNC void virt_viewer_auth_vnc_credentials(GtkWidget *vnc, - GValueArray *credList, - char **vncAddress) + GValueArray *credList, + char **vncAddress) { - char *username = NULL, *password = NULL; - gboolean wantPassword = FALSE, wantUsername = FALSE; - int i; - - DEBUG_LOG("Got VNC credential request for %d credential(s)", credList->n_values); - - for (i = 0 ; i < credList->n_values ; i++) { - GValue *cred = g_value_array_get_nth(credList, i); - switch (g_value_get_enum(cred)) { - case VNC_DISPLAY_CREDENTIAL_USERNAME: - wantUsername = TRUE; - break; - case VNC_DISPLAY_CREDENTIAL_PASSWORD: - wantPassword = TRUE; - break; - case VNC_DISPLAY_CREDENTIAL_CLIENTNAME: - break; - default: - DEBUG_LOG("Unsupported credential type %d", g_value_get_enum(cred)); - vnc_display_close(VNC_DISPLAY(vnc)); - goto cleanup; - } + char *username = NULL, *password = NULL; + gboolean wantPassword = FALSE, wantUsername = FALSE; + int i; + + DEBUG_LOG("Got VNC credential request for %d credential(s)", credList->n_values); + + for (i = 0 ; i < credList->n_values ; i++) { + GValue *cred = g_value_array_get_nth(credList, i); + switch (g_value_get_enum(cred)) { + case VNC_DISPLAY_CREDENTIAL_USERNAME: + wantUsername = TRUE; + break; + case VNC_DISPLAY_CREDENTIAL_PASSWORD: + wantPassword = TRUE; + break; + case VNC_DISPLAY_CREDENTIAL_CLIENTNAME: + break; + default: + DEBUG_LOG("Unsupported credential type %d", g_value_get_enum(cred)); + vnc_display_close(VNC_DISPLAY(vnc)); + goto cleanup; } + } - if (wantUsername || wantPassword) { - int ret = virt_viewer_auth_collect_credentials("VNC", vncAddress ? *vncAddress : NULL, - wantUsername ? &username : NULL, - wantPassword ? &password : NULL); + if (wantUsername || wantPassword) { + int ret = virt_viewer_auth_collect_credentials("VNC", vncAddress ? *vncAddress : NULL, + wantUsername ? &username : NULL, + wantPassword ? &password : NULL); - if (ret < 0) { - vnc_display_close(VNC_DISPLAY(vnc)); - goto cleanup; - } + if (ret < 0) { + vnc_display_close(VNC_DISPLAY(vnc)); + goto cleanup; } - - for (i = 0 ; i < credList->n_values ; i++) { - GValue *cred = g_value_array_get_nth(credList, i); - switch (g_value_get_enum(cred)) { - case VNC_DISPLAY_CREDENTIAL_USERNAME: - if (!username || - vnc_display_set_credential(VNC_DISPLAY(vnc), - g_value_get_enum(cred), - username)) { - DEBUG_LOG("Failed to set credential type %d", g_value_get_enum(cred)); - vnc_display_close(VNC_DISPLAY(vnc)); - } - break; - case VNC_DISPLAY_CREDENTIAL_PASSWORD: - if (!password || - vnc_display_set_credential(VNC_DISPLAY(vnc), - g_value_get_enum(cred), - password)) { - DEBUG_LOG("Failed to set credential type %d", g_value_get_enum(cred)); - vnc_display_close(VNC_DISPLAY(vnc)); - } - break; - case VNC_DISPLAY_CREDENTIAL_CLIENTNAME: - if (vnc_display_set_credential(VNC_DISPLAY(vnc), - g_value_get_enum(cred), - "libvirt")) { - DEBUG_LOG("Failed to set credential type %d", g_value_get_enum(cred)); - vnc_display_close(VNC_DISPLAY(vnc)); - } - break; - default: - DEBUG_LOG("Unsupported credential type %d", g_value_get_enum(cred)); - vnc_display_close(VNC_DISPLAY(vnc)); - } + } + + for (i = 0 ; i < credList->n_values ; i++) { + GValue *cred = g_value_array_get_nth(credList, i); + switch (g_value_get_enum(cred)) { + case VNC_DISPLAY_CREDENTIAL_USERNAME: + if (!username || + vnc_display_set_credential(VNC_DISPLAY(vnc), + g_value_get_enum(cred), + username)) { + DEBUG_LOG("Failed to set credential type %d", g_value_get_enum(cred)); + vnc_display_close(VNC_DISPLAY(vnc)); + } + break; + case VNC_DISPLAY_CREDENTIAL_PASSWORD: + if (!password || + vnc_display_set_credential(VNC_DISPLAY(vnc), + g_value_get_enum(cred), + password)) { + DEBUG_LOG("Failed to set credential type %d", g_value_get_enum(cred)); + vnc_display_close(VNC_DISPLAY(vnc)); + } + break; + case VNC_DISPLAY_CREDENTIAL_CLIENTNAME: + if (vnc_display_set_credential(VNC_DISPLAY(vnc), + g_value_get_enum(cred), + "libvirt")) { + DEBUG_LOG("Failed to set credential type %d", g_value_get_enum(cred)); + vnc_display_close(VNC_DISPLAY(vnc)); + } + break; + default: + DEBUG_LOG("Unsupported credential type %d", g_value_get_enum(cred)); + vnc_display_close(VNC_DISPLAY(vnc)); } + } cleanup: - g_free(username); - g_free(password); + g_free(username); + g_free(password); } #endif @@ -177,66 +177,64 @@ virt_viewer_auth_vnc_credentials(GtkWidget *vnc, #ifdef HAVE_LIBVIRT int virt_viewer_auth_libvirt_credentials(virConnectCredentialPtr cred, - unsigned int ncred, - void *cbdata) + unsigned int ncred, + void *cbdata) { - char **username = NULL, **password = NULL; - const char *uri = cbdata; - int i; - int ret = -1; - - DEBUG_LOG("Got libvirt credential request for %d credential(s)", ncred); - - for (i = 0 ; i < ncred ; i++) { - switch (cred[i].type) { - case VIR_CRED_USERNAME: - case VIR_CRED_AUTHNAME: - username = &cred[i].result; - break; - case VIR_CRED_PASSPHRASE: - password = &cred[i].result; - break; - default: - DEBUG_LOG("Unsupported libvirt credential %d", cred[i].type); - return -1; - } + char **username = NULL, **password = NULL; + const char *uri = cbdata; + int i; + int ret = -1; + + DEBUG_LOG("Got libvirt credential request for %d credential(s)", ncred); + + for (i = 0 ; i < ncred ; i++) { + switch (cred[i].type) { + case VIR_CRED_USERNAME: + case VIR_CRED_AUTHNAME: + username = &cred[i].result; + break; + case VIR_CRED_PASSPHRASE: + password = &cred[i].result; + break; + default: + DEBUG_LOG("Unsupported libvirt credential %d", cred[i].type); + return -1; } - - if (username || password) { - ret = virt_viewer_auth_collect_credentials("libvirt", uri, - username, password); - if (ret < 0) - goto cleanup; - } else { - ret = 0; - } - - for (i = 0 ; i < ncred ; i++) { - switch (cred[i].type) { - case VIR_CRED_AUTHNAME: - case VIR_CRED_USERNAME: - case VIR_CRED_PASSPHRASE: - if (cred[i].result) - cred[i].resultlen = strlen(cred[i].result); - else - cred[i].resultlen = 0; - DEBUG_LOG("Got '%s' %d %d", cred[i].result, cred[i].resultlen, cred[i].type); - break; - } + } + + if (username || password) { + ret = virt_viewer_auth_collect_credentials("libvirt", uri, + username, password); + if (ret < 0) + goto cleanup; + } else { + ret = 0; + } + + for (i = 0 ; i < ncred ; i++) { + switch (cred[i].type) { + case VIR_CRED_AUTHNAME: + case VIR_CRED_USERNAME: + case VIR_CRED_PASSPHRASE: + if (cred[i].result) + cred[i].resultlen = strlen(cred[i].result); + else + cred[i].resultlen = 0; + DEBUG_LOG("Got '%s' %d %d", cred[i].result, cred[i].resultlen, cred[i].type); + break; } + } cleanup: - DEBUG_LOG("Return %d", ret); - return ret; + DEBUG_LOG("Return %d", ret); + return ret; } #endif - - /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/virt-viewer-auth.h b/src/virt-viewer-auth.h index c111582..706da1b 100644 --- a/src/virt-viewer-auth.h +++ b/src/virt-viewer-auth.h @@ -32,18 +32,25 @@ #include "virt-viewer-util.h" void virt_viewer_auth_vnc_credentials(GtkWidget *vnc, - GValueArray *credList, - char **message); + GValueArray *credList, + char **message); int virt_viewer_auth_collect_credentials(const char *type, - const char *address, - char **username, - char **password); + const char *address, + char **username, + char **password); #ifdef HAVE_LIBVIRT int virt_viewer_auth_libvirt_credentials(virConnectCredentialPtr cred, - unsigned int ncred, - void *cbdata); + unsigned int ncred, + void *cbdata); #endif #endif +/* + * Local variables: + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/src/virt-viewer-display-spice.c b/src/virt-viewer-display-spice.c index 7c25ead..963b354 100644 --- a/src/virt-viewer-display-spice.c +++ b/src/virt-viewer-display-spice.c @@ -33,171 +33,170 @@ G_DEFINE_TYPE (VirtViewerDisplaySpice, virt_viewer_display_spice, VIRT_VIEWER_TYPE_DISPLAY) struct _VirtViewerDisplaySpicePrivate { - SpiceChannel *channel; - SpiceDisplay *display; + SpiceChannel *channel; + SpiceDisplay *display; }; #define VIRT_VIEWER_DISPLAY_SPICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), VIRT_VIEWER_TYPE_DISPLAY_SPICE, VirtViewerDisplaySpicePrivate)) static void virt_viewer_display_spice_send_keys(VirtViewerDisplay *display, - const guint *keyvals, - int nkeyvals); + const guint *keyvals, + int nkeyvals); static GdkPixbuf *virt_viewer_display_spice_get_pixbuf(VirtViewerDisplay *display); static void virt_viewer_display_spice_finalize(GObject *obj) { - VirtViewerDisplaySpice *spice = VIRT_VIEWER_DISPLAY_SPICE(obj); + VirtViewerDisplaySpice *spice = VIRT_VIEWER_DISPLAY_SPICE(obj); - g_object_unref(spice->priv->display); - g_object_unref(spice->priv->channel); + g_object_unref(spice->priv->display); + g_object_unref(spice->priv->channel); - G_OBJECT_CLASS(virt_viewer_display_spice_parent_class)->finalize(obj); + G_OBJECT_CLASS(virt_viewer_display_spice_parent_class)->finalize(obj); } static void virt_viewer_display_spice_class_init(VirtViewerDisplaySpiceClass *klass) { - VirtViewerDisplayClass *dclass = VIRT_VIEWER_DISPLAY_CLASS(klass); - GObjectClass *oclass = G_OBJECT_CLASS(klass); + VirtViewerDisplayClass *dclass = VIRT_VIEWER_DISPLAY_CLASS(klass); + GObjectClass *oclass = G_OBJECT_CLASS(klass); - oclass->finalize = virt_viewer_display_spice_finalize; + oclass->finalize = virt_viewer_display_spice_finalize; - dclass->send_keys = virt_viewer_display_spice_send_keys; - dclass->get_pixbuf = virt_viewer_display_spice_get_pixbuf; + dclass->send_keys = virt_viewer_display_spice_send_keys; + dclass->get_pixbuf = virt_viewer_display_spice_get_pixbuf; - g_type_class_add_private(klass, sizeof(VirtViewerDisplaySpicePrivate)); + g_type_class_add_private(klass, sizeof(VirtViewerDisplaySpicePrivate)); } static void virt_viewer_display_spice_init(VirtViewerDisplaySpice *self G_GNUC_UNUSED) { - self->priv = VIRT_VIEWER_DISPLAY_SPICE_GET_PRIVATE(self); + self->priv = VIRT_VIEWER_DISPLAY_SPICE_GET_PRIVATE(self); - virt_viewer_display_set_maintain_aspect_ratio(VIRT_VIEWER_DISPLAY(self), FALSE); + virt_viewer_display_set_maintain_aspect_ratio(VIRT_VIEWER_DISPLAY(self), FALSE); } static void virt_viewer_display_spice_send_keys(VirtViewerDisplay *display, - const guint *keyvals, - int nkeyvals) + const guint *keyvals, + int nkeyvals) { - VirtViewerDisplaySpice *self = VIRT_VIEWER_DISPLAY_SPICE(display); + VirtViewerDisplaySpice *self = VIRT_VIEWER_DISPLAY_SPICE(display); - g_return_if_fail(self != NULL); - g_return_if_fail(self->priv->display != NULL); + g_return_if_fail(self != NULL); + g_return_if_fail(self->priv->display != NULL); - spice_display_send_keys(self->priv->display, keyvals, nkeyvals, SPICE_DISPLAY_KEY_EVENT_CLICK); + spice_display_send_keys(self->priv->display, keyvals, nkeyvals, SPICE_DISPLAY_KEY_EVENT_CLICK); } static GdkPixbuf * virt_viewer_display_spice_get_pixbuf(VirtViewerDisplay *display) { - VirtViewerDisplaySpice *self = VIRT_VIEWER_DISPLAY_SPICE(display); + VirtViewerDisplaySpice *self = VIRT_VIEWER_DISPLAY_SPICE(display); - g_return_val_if_fail(self != NULL, NULL); - g_return_val_if_fail(self->priv->display != NULL, NULL); + g_return_val_if_fail(self != NULL, NULL); + g_return_val_if_fail(self->priv->display != NULL, NULL); - return spice_display_get_pixbuf(self->priv->display); + return spice_display_get_pixbuf(self->priv->display); } static void display_mark(SpiceChannel *channel G_GNUC_UNUSED, - gint mark, - VirtViewerDisplay *display) + gint mark, + VirtViewerDisplay *display) { - DEBUG_LOG("display mark %d", mark); + DEBUG_LOG("display mark %d", mark); - virt_viewer_display_set_show_hint(display, mark); + virt_viewer_display_set_show_hint(display, mark); } static void primary_create(SpiceChannel *channel G_GNUC_UNUSED, - gint format G_GNUC_UNUSED, - gint width, - gint height, - gint stride G_GNUC_UNUSED, - gint shmid G_GNUC_UNUSED, - gpointer imgdata G_GNUC_UNUSED, - VirtViewerDisplay *display) + gint format G_GNUC_UNUSED, + gint width, + gint height, + gint stride G_GNUC_UNUSED, + gint shmid G_GNUC_UNUSED, + gpointer imgdata G_GNUC_UNUSED, + VirtViewerDisplay *display) { - DEBUG_LOG("spice desktop resize %dx%d", width, height); + DEBUG_LOG("spice desktop resize %dx%d", width, height); - virt_viewer_display_set_desktop_size(display, width, height); + virt_viewer_display_set_desktop_size(display, width, height); } static void virt_viewer_display_spice_keyboard_grab(SpiceDisplay *display G_GNUC_UNUSED, - int grabbed, - VirtViewerDisplaySpice *self) + int grabbed, + VirtViewerDisplaySpice *self) { - if (grabbed) - g_signal_emit_by_name(self, "display-keyboard-grab"); - else - g_signal_emit_by_name(self, "display-keyboard-ungrab"); + if (grabbed) + g_signal_emit_by_name(self, "display-keyboard-grab"); + else + g_signal_emit_by_name(self, "display-keyboard-ungrab"); } static void virt_viewer_display_spice_mouse_grab(SpiceDisplay *display G_GNUC_UNUSED, - int grabbed, - VirtViewerDisplaySpice *self) + int grabbed, + VirtViewerDisplaySpice *self) { - if (grabbed) - g_signal_emit_by_name(self, "display-pointer-grab"); - else - g_signal_emit_by_name(self, "display-pointer-ungrab"); + if (grabbed) + g_signal_emit_by_name(self, "display-pointer-grab"); + else + g_signal_emit_by_name(self, "display-pointer-ungrab"); } GtkWidget * virt_viewer_display_spice_new(SpiceChannel *channel, - SpiceDisplay *display) + SpiceDisplay *display) { - VirtViewerDisplaySpice *self; - gint channelid; - - g_return_val_if_fail(SPICE_IS_DISPLAY_CHANNEL(channel), NULL); - g_return_val_if_fail(SPICE_IS_DISPLAY(display), NULL); - - g_object_get(channel, "channel-id", &channelid, NULL); - - self = g_object_new(VIRT_VIEWER_TYPE_DISPLAY_SPICE, - "nth-display", channelid, - NULL); - self->priv->channel = g_object_ref(channel); - self->priv->display = g_object_ref(display); - - g_signal_connect(channel, "display-primary-create", - G_CALLBACK(primary_create), self); - g_signal_connect(channel, "display-mark", - G_CALLBACK(display_mark), self); - - gtk_container_add(GTK_CONTAINER(self), GTK_WIDGET(self->priv->display)); - gtk_widget_show(GTK_WIDGET(self->priv->display)); - g_object_set(self->priv->display, - "grab-keyboard", TRUE, - "grab-mouse", TRUE, - "scaling", TRUE, - "resize-guest", TRUE, - NULL); - - g_signal_connect(self->priv->display, - "keyboard-grab", - G_CALLBACK(virt_viewer_display_spice_keyboard_grab), self); - g_signal_connect(self->priv->display, - "mouse-grab", - G_CALLBACK(virt_viewer_display_spice_mouse_grab), self); - - return GTK_WIDGET(self); + VirtViewerDisplaySpice *self; + gint channelid; + + g_return_val_if_fail(SPICE_IS_DISPLAY_CHANNEL(channel), NULL); + g_return_val_if_fail(SPICE_IS_DISPLAY(display), NULL); + + g_object_get(channel, "channel-id", &channelid, NULL); + + self = g_object_new(VIRT_VIEWER_TYPE_DISPLAY_SPICE, + "nth-display", channelid, + NULL); + self->priv->channel = g_object_ref(channel); + self->priv->display = g_object_ref(display); + + g_signal_connect(channel, "display-primary-create", + G_CALLBACK(primary_create), self); + g_signal_connect(channel, "display-mark", + G_CALLBACK(display_mark), self); + + gtk_container_add(GTK_CONTAINER(self), GTK_WIDGET(self->priv->display)); + gtk_widget_show(GTK_WIDGET(self->priv->display)); + g_object_set(self->priv->display, + "grab-keyboard", TRUE, + "grab-mouse", TRUE, + "scaling", TRUE, + "resize-guest", TRUE, + NULL); + + g_signal_connect(self->priv->display, + "keyboard-grab", + G_CALLBACK(virt_viewer_display_spice_keyboard_grab), self); + g_signal_connect(self->priv->display, + "mouse-grab", + G_CALLBACK(virt_viewer_display_spice_mouse_grab), self); + + return GTK_WIDGET(self); } /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 - * indent-tabs-mode: t + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/virt-viewer-display-spice.h b/src/virt-viewer-display-spice.h index 90bd1d0..2f4f985 100644 --- a/src/virt-viewer-display-spice.h +++ b/src/virt-viewer-display-spice.h @@ -34,48 +34,47 @@ G_BEGIN_DECLS #define VIRT_VIEWER_TYPE_DISPLAY_SPICE virt_viewer_display_spice_get_type() -#define VIRT_VIEWER_DISPLAY_SPICE(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIRT_VIEWER_TYPE_DISPLAY_SPICE, VirtViewerDisplaySpice)) +#define VIRT_VIEWER_DISPLAY_SPICE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIRT_VIEWER_TYPE_DISPLAY_SPICE, VirtViewerDisplaySpice)) -#define VIRT_VIEWER_DISPLAY_SPICE_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), VIRT_VIEWER_TYPE_DISPLAY_SPICE, VirtViewerDisplaySpiceClass)) +#define VIRT_VIEWER_DISPLAY_SPICE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), VIRT_VIEWER_TYPE_DISPLAY_SPICE, VirtViewerDisplaySpiceClass)) -#define VIRT_VIEWER_IS_DISPLAY_SPICE(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIRT_VIEWER_TYPE_DISPLAY_SPICE)) +#define VIRT_VIEWER_IS_DISPLAY_SPICE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIRT_VIEWER_TYPE_DISPLAY_SPICE)) -#define VIRT_VIEWER_IS_DISPLAY_SPICE_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), VIRT_VIEWER_TYPE_DISPLAY_SPICE)) +#define VIRT_VIEWER_IS_DISPLAY_SPICE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), VIRT_VIEWER_TYPE_DISPLAY_SPICE)) -#define VIRT_VIEWER_DISPLAY_SPICE_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), VIRT_VIEWER_TYPE_DISPLAY_SPICE, VirtViewerDisplaySpiceClass)) +#define VIRT_VIEWER_DISPLAY_SPICE_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), VIRT_VIEWER_TYPE_DISPLAY_SPICE, VirtViewerDisplaySpiceClass)) typedef struct _VirtViewerDisplaySpice VirtViewerDisplaySpice; typedef struct _VirtViewerDisplaySpiceClass VirtViewerDisplaySpiceClass; typedef struct _VirtViewerDisplaySpicePrivate VirtViewerDisplaySpicePrivate; struct _VirtViewerDisplaySpice { - VirtViewerDisplay parent; + VirtViewerDisplay parent; - VirtViewerDisplaySpicePrivate *priv; + VirtViewerDisplaySpicePrivate *priv; }; struct _VirtViewerDisplaySpiceClass { - VirtViewerDisplayClass parent_class; + VirtViewerDisplayClass parent_class; }; GType virt_viewer_display_spice_get_type(void); GtkWidget* virt_viewer_display_spice_new(SpiceChannel *channel, - SpiceDisplay *display); + SpiceDisplay *display); G_END_DECLS #endif /* _VIRT_VIEWER_DISPLAY_SPICE_H */ - /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/virt-viewer-display-vnc.c b/src/virt-viewer-display-vnc.c index 3228348..bfc0287 100644 --- a/src/virt-viewer-display-vnc.c +++ b/src/virt-viewer-display-vnc.c @@ -30,7 +30,7 @@ G_DEFINE_TYPE(VirtViewerDisplayVnc, virt_viewer_display_vnc, VIRT_VIEWER_TYPE_DISPLAY) struct _VirtViewerDisplayVncPrivate { - VncDisplay *vnc; + VncDisplay *vnc; }; #define VIRT_VIEWER_DISPLAY_VNC_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), VIRT_VIEWER_TYPE_DISPLAY_VNC, VirtViewerDisplayVncPrivate)) @@ -41,88 +41,88 @@ static GdkPixbuf *virt_viewer_display_vnc_get_pixbuf(VirtViewerDisplay* display) static void virt_viewer_display_vnc_finalize(GObject *obj) { - VirtViewerDisplayVnc *vnc = VIRT_VIEWER_DISPLAY_VNC(obj); + VirtViewerDisplayVnc *vnc = VIRT_VIEWER_DISPLAY_VNC(obj); - g_object_unref(vnc->priv->vnc); + g_object_unref(vnc->priv->vnc); - G_OBJECT_CLASS(virt_viewer_display_vnc_parent_class)->finalize(obj); + G_OBJECT_CLASS(virt_viewer_display_vnc_parent_class)->finalize(obj); } static void virt_viewer_display_vnc_class_init(VirtViewerDisplayVncClass *klass) { - VirtViewerDisplayClass *dclass = VIRT_VIEWER_DISPLAY_CLASS(klass); - GObjectClass *oclass = G_OBJECT_CLASS(klass); + VirtViewerDisplayClass *dclass = VIRT_VIEWER_DISPLAY_CLASS(klass); + GObjectClass *oclass = G_OBJECT_CLASS(klass); - oclass->finalize = virt_viewer_display_vnc_finalize; + oclass->finalize = virt_viewer_display_vnc_finalize; - dclass->send_keys = virt_viewer_display_vnc_send_keys; - dclass->get_pixbuf = virt_viewer_display_vnc_get_pixbuf; + dclass->send_keys = virt_viewer_display_vnc_send_keys; + dclass->get_pixbuf = virt_viewer_display_vnc_get_pixbuf; - g_type_class_add_private(klass, sizeof(VirtViewerDisplayVncPrivate)); + g_type_class_add_private(klass, sizeof(VirtViewerDisplayVncPrivate)); } static void virt_viewer_display_vnc_init(VirtViewerDisplayVnc *self G_GNUC_UNUSED) { - self->priv = VIRT_VIEWER_DISPLAY_VNC_GET_PRIVATE(self); + self->priv = VIRT_VIEWER_DISPLAY_VNC_GET_PRIVATE(self); } static void virt_viewer_display_vnc_mouse_grab(VncDisplay *vnc G_GNUC_UNUSED, - VirtViewerDisplay *display) + VirtViewerDisplay *display) { - g_signal_emit_by_name(display, "display-pointer-grab"); + g_signal_emit_by_name(display, "display-pointer-grab"); } static void virt_viewer_display_vnc_mouse_ungrab(VncDisplay *vnc G_GNUC_UNUSED, - VirtViewerDisplay *display) + VirtViewerDisplay *display) { - g_signal_emit_by_name(display, "display-pointer-ungrab"); + g_signal_emit_by_name(display, "display-pointer-ungrab"); } static void virt_viewer_display_vnc_key_grab(VncDisplay *vnc G_GNUC_UNUSED, - VirtViewerDisplay *display) + VirtViewerDisplay *display) { - g_signal_emit_by_name(display, "display-keyboard-grab"); + g_signal_emit_by_name(display, "display-keyboard-grab"); } static void virt_viewer_display_vnc_key_ungrab(VncDisplay *vnc G_GNUC_UNUSED, - VirtViewerDisplay *display) + VirtViewerDisplay *display) { - g_signal_emit_by_name(display, "display-keyboard-ungrab"); + g_signal_emit_by_name(display, "display-keyboard-ungrab"); } static void virt_viewer_display_vnc_send_keys(VirtViewerDisplay* display, - const guint *keyvals, - int nkeyvals) + const guint *keyvals, + int nkeyvals) { - VirtViewerDisplayVnc *self = VIRT_VIEWER_DISPLAY_VNC(display); + VirtViewerDisplayVnc *self = VIRT_VIEWER_DISPLAY_VNC(display); - g_return_if_fail(self != NULL); - g_return_if_fail(keyvals != NULL); - g_return_if_fail(self->priv->vnc != NULL); + g_return_if_fail(self != NULL); + g_return_if_fail(keyvals != NULL); + g_return_if_fail(self->priv->vnc != NULL); - vnc_display_send_keys(self->priv->vnc, keyvals, nkeyvals); + vnc_display_send_keys(self->priv->vnc, keyvals, nkeyvals); } static GdkPixbuf * virt_viewer_display_vnc_get_pixbuf(VirtViewerDisplay* display) { - VirtViewerDisplayVnc *self = VIRT_VIEWER_DISPLAY_VNC(display); + VirtViewerDisplayVnc *self = VIRT_VIEWER_DISPLAY_VNC(display); - g_return_val_if_fail(self != NULL, NULL); - g_return_val_if_fail(self->priv->vnc != NULL, NULL); + g_return_val_if_fail(self != NULL, NULL); + g_return_val_if_fail(self->priv->vnc != NULL, NULL); - return vnc_display_get_pixbuf(self->priv->vnc); + return vnc_display_get_pixbuf(self->priv->vnc); } @@ -134,65 +134,62 @@ virt_viewer_display_vnc_get_pixbuf(VirtViewerDisplay* display) */ static void virt_viewer_display_vnc_resize_desktop(VncDisplay *vnc G_GNUC_UNUSED, - int width, int height, - VirtViewerDisplay *display) + int width, int height, + VirtViewerDisplay *display) { - DEBUG_LOG("desktop resize %dx%d", width, height); + DEBUG_LOG("desktop resize %dx%d", width, height); - virt_viewer_display_set_desktop_size(display, width, height); + virt_viewer_display_set_desktop_size(display, width, height); } GtkWidget * virt_viewer_display_vnc_new(VncDisplay *vnc) { - VirtViewerDisplayVnc *display; - - display = g_object_new(VIRT_VIEWER_TYPE_DISPLAY_VNC, NULL); - - g_object_ref(vnc); - g_object_ref(vnc); /* Because gtk_container_add steals the first ref */ - display->priv->vnc = vnc; - - gtk_container_add(GTK_CONTAINER(display), GTK_WIDGET(display->priv->vnc)); - vnc_display_set_keyboard_grab(display->priv->vnc, TRUE); - vnc_display_set_pointer_grab(display->priv->vnc, TRUE); - - /* - * In auto-resize mode we have things setup so that we always - * automatically resize the top level window to be exactly the - * same size as the VNC desktop, except when it won't fit on - * the local screen, at which point we let it scale down. - * The upshot is, we always want scaling enabled. - * We disable force_size because we want to allow user to - * manually size the widget smaller too - */ - vnc_display_set_force_size(display->priv->vnc, FALSE); - vnc_display_set_scaling(display->priv->vnc, TRUE); - - /* When VNC desktop resizes, we have to resize the containing widget */ - g_signal_connect(display->priv->vnc, "vnc-desktop-resize", - G_CALLBACK(virt_viewer_display_vnc_resize_desktop), display); - - g_signal_connect(display->priv->vnc, "vnc-pointer-grab", - G_CALLBACK(virt_viewer_display_vnc_mouse_grab), display); - g_signal_connect(display->priv->vnc, "vnc-pointer-ungrab", - G_CALLBACK(virt_viewer_display_vnc_mouse_ungrab), display); - g_signal_connect(display->priv->vnc, "vnc-keyboard-grab", - G_CALLBACK(virt_viewer_display_vnc_key_grab), display); - g_signal_connect(display->priv->vnc, "vnc-keyboard-ungrab", - G_CALLBACK(virt_viewer_display_vnc_key_ungrab), display); - - return GTK_WIDGET(display); + VirtViewerDisplayVnc *display; + + display = g_object_new(VIRT_VIEWER_TYPE_DISPLAY_VNC, NULL); + + g_object_ref(vnc); + g_object_ref(vnc); /* Because gtk_container_add steals the first ref */ + display->priv->vnc = vnc; + + gtk_container_add(GTK_CONTAINER(display), GTK_WIDGET(display->priv->vnc)); + vnc_display_set_keyboard_grab(display->priv->vnc, TRUE); + vnc_display_set_pointer_grab(display->priv->vnc, TRUE); + + /* + * In auto-resize mode we have things setup so that we always + * automatically resize the top level window to be exactly the + * same size as the VNC desktop, except when it won't fit on + * the local screen, at which point we let it scale down. + * The upshot is, we always want scaling enabled. + * We disable force_size because we want to allow user to + * manually size the widget smaller too + */ + vnc_display_set_force_size(display->priv->vnc, FALSE); + vnc_display_set_scaling(display->priv->vnc, TRUE); + + /* When VNC desktop resizes, we have to resize the containing widget */ + g_signal_connect(display->priv->vnc, "vnc-desktop-resize", + G_CALLBACK(virt_viewer_display_vnc_resize_desktop), display); + + g_signal_connect(display->priv->vnc, "vnc-pointer-grab", + G_CALLBACK(virt_viewer_display_vnc_mouse_grab), display); + g_signal_connect(display->priv->vnc, "vnc-pointer-ungrab", + G_CALLBACK(virt_viewer_display_vnc_mouse_ungrab), display); + g_signal_connect(display->priv->vnc, "vnc-keyboard-grab", + G_CALLBACK(virt_viewer_display_vnc_key_grab), display); + g_signal_connect(display->priv->vnc, "vnc-keyboard-ungrab", + G_CALLBACK(virt_viewer_display_vnc_key_ungrab), display); + + return GTK_WIDGET(display); } - - - /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/virt-viewer-display-vnc.h b/src/virt-viewer-display-vnc.h index ce9ec5f..bdc995d 100644 --- a/src/virt-viewer-display-vnc.h +++ b/src/virt-viewer-display-vnc.h @@ -33,33 +33,33 @@ G_BEGIN_DECLS #define VIRT_VIEWER_TYPE_DISPLAY_VNC virt_viewer_display_vnc_get_type() -#define VIRT_VIEWER_DISPLAY_VNC(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIRT_VIEWER_TYPE_DISPLAY_VNC, VirtViewerDisplayVnc)) +#define VIRT_VIEWER_DISPLAY_VNC(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIRT_VIEWER_TYPE_DISPLAY_VNC, VirtViewerDisplayVnc)) -#define VIRT_VIEWER_DISPLAY_VNC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), VIRT_VIEWER_TYPE_DISPLAY_VNC, VirtViewerDisplayVncClass)) +#define VIRT_VIEWER_DISPLAY_VNC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), VIRT_VIEWER_TYPE_DISPLAY_VNC, VirtViewerDisplayVncClass)) -#define VIRT_VIEWER_IS_DISPLAY_VNC(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIRT_VIEWER_TYPE_DISPLAY_VNC)) +#define VIRT_VIEWER_IS_DISPLAY_VNC(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIRT_VIEWER_TYPE_DISPLAY_VNC)) -#define VIRT_VIEWER_IS_DISPLAY_VNC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), VIRT_VIEWER_TYPE_DISPLAY_VNC)) +#define VIRT_VIEWER_IS_DISPLAY_VNC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), VIRT_VIEWER_TYPE_DISPLAY_VNC)) -#define VIRT_VIEWER_DISPLAY_VNC_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), VIRT_VIEWER_TYPE_DISPLAY_VNC, VirtViewerDisplayVncClass)) +#define VIRT_VIEWER_DISPLAY_VNC_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), VIRT_VIEWER_TYPE_DISPLAY_VNC, VirtViewerDisplayVncClass)) typedef struct _VirtViewerDisplayVnc VirtViewerDisplayVnc; typedef struct _VirtViewerDisplayVncClass VirtViewerDisplayVncClass; typedef struct _VirtViewerDisplayVncPrivate VirtViewerDisplayVncPrivate; struct _VirtViewerDisplayVnc { - VirtViewerDisplay parent; + VirtViewerDisplay parent; - VirtViewerDisplayVncPrivate *priv; + VirtViewerDisplayVncPrivate *priv; }; struct _VirtViewerDisplayVncClass { - VirtViewerDisplayClass parent_class; + VirtViewerDisplayClass parent_class; }; GType virt_viewer_display_vnc_get_type(void); @@ -69,11 +69,10 @@ GtkWidget* virt_viewer_display_vnc_new(VncDisplay *display); G_END_DECLS #endif /* _VIRT_VIEWER_DISPLAY_VNC_H */ - /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/virt-viewer-display.c b/src/virt-viewer-display.c index 7f821e5..22a4602 100644 --- a/src/virt-viewer-display.c +++ b/src/virt-viewer-display.c @@ -33,503 +33,503 @@ struct _VirtViewerDisplayPrivate { - gboolean dirty; - guint desktopWidth; - guint desktopHeight; - guint zoom_level; - gboolean zoom; - gint nth_display; - gint show_hint; - gboolean maintain_aspect_ratio; + gboolean dirty; + guint desktopWidth; + guint desktopHeight; + guint zoom_level; + gboolean zoom; + gint nth_display; + gint show_hint; + gboolean maintain_aspect_ratio; }; static void virt_viewer_display_size_request(GtkWidget *widget, - GtkRequisition *requisition); + GtkRequisition *requisition); #if GTK_CHECK_VERSION(3, 0, 0) static void virt_viewer_display_get_preferred_width(GtkWidget *widget, - int *minwidth, - int *defwidth); + int *minwidth, + int *defwidth); static void virt_viewer_display_get_preferred_height(GtkWidget *widget, - int *minheight, - int *defheight); + int *minheight, + int *defheight); #endif static void virt_viewer_display_size_allocate(GtkWidget *widget, - GtkAllocation *allocation); + GtkAllocation *allocation); static void virt_viewer_display_set_property(GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); + guint prop_id, + const GValue *value, + GParamSpec *pspec); static void virt_viewer_display_get_property(GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); + guint prop_id, + GValue *value, + GParamSpec *pspec); static void virt_viewer_display_grab_focus(GtkWidget *widget); G_DEFINE_ABSTRACT_TYPE(VirtViewerDisplay, virt_viewer_display, GTK_TYPE_BIN) enum { - PROP_0, - - PROP_DESKTOP_WIDTH, - PROP_DESKTOP_HEIGHT, - PROP_NTH_DISPLAY, - PROP_ZOOM, - PROP_ZOOM_LEVEL, - PROP_SHOW_HINT, + PROP_0, + + PROP_DESKTOP_WIDTH, + PROP_DESKTOP_HEIGHT, + PROP_NTH_DISPLAY, + PROP_ZOOM, + PROP_ZOOM_LEVEL, + PROP_SHOW_HINT, }; static void virt_viewer_display_class_init(VirtViewerDisplayClass *class) { - GObjectClass *object_class = G_OBJECT_CLASS(class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(class); + GObjectClass *object_class = G_OBJECT_CLASS(class); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(class); - object_class->set_property = virt_viewer_display_set_property; - object_class->get_property = virt_viewer_display_get_property; + object_class->set_property = virt_viewer_display_set_property; + object_class->get_property = virt_viewer_display_get_property; #if GTK_CHECK_VERSION(3, 0, 0) - widget_class->get_preferred_width = virt_viewer_display_get_preferred_width; - widget_class->get_preferred_height = virt_viewer_display_get_preferred_height; + widget_class->get_preferred_width = virt_viewer_display_get_preferred_width; + widget_class->get_preferred_height = virt_viewer_display_get_preferred_height; #else - widget_class->size_request = virt_viewer_display_size_request; + widget_class->size_request = virt_viewer_display_size_request; #endif - widget_class->size_allocate = virt_viewer_display_size_allocate; - widget_class->grab_focus = virt_viewer_display_grab_focus; - - g_object_class_install_property(object_class, - PROP_DESKTOP_WIDTH, - g_param_spec_int("desktop-width", - "Width", - "Desktop width", - 100, - G_MAXINT32, - 100, - G_PARAM_READWRITE)); - - g_object_class_install_property(object_class, - PROP_DESKTOP_HEIGHT, - g_param_spec_int("desktop-height", - "Height", - "Desktop height", - 100, - G_MAXINT32, - 100, - G_PARAM_READWRITE)); - - g_object_class_install_property(object_class, - PROP_ZOOM, - g_param_spec_boolean("zoom", - "Zoom", - "Zoom", - TRUE, - G_PARAM_READWRITE)); - - g_object_class_install_property(object_class, - PROP_ZOOM_LEVEL, - g_param_spec_int("zoom-level", - "Zoom", - "Zoom level", - 10, - 400, - 100, - G_PARAM_READWRITE)); - - g_object_class_install_property(object_class, - PROP_NTH_DISPLAY, - g_param_spec_int("nth-display", - "Nth display", - "Nth display", - 0, - G_MAXINT32, - 0, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property(object_class, - PROP_SHOW_HINT, - g_param_spec_int("show-hint", - "Show hint", - "Show state hint", - 0, - G_MAXINT32, - 0, - G_PARAM_READABLE)); - - - g_signal_new("display-pointer-grab", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, - G_STRUCT_OFFSET(VirtViewerDisplayClass, display_pointer_grab), - NULL, - NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - g_signal_new("display-pointer-ungrab", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, - G_STRUCT_OFFSET(VirtViewerDisplayClass, display_pointer_ungrab), - NULL, - NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - g_signal_new("display-keyboard-grab", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, - G_STRUCT_OFFSET(VirtViewerDisplayClass, display_keyboard_grab), - NULL, - NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - g_signal_new("display-keyboard-ungrab", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, - G_STRUCT_OFFSET(VirtViewerDisplayClass, display_keyboard_ungrab), - NULL, - NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - g_signal_new("display-desktop-resize", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, - G_STRUCT_OFFSET(VirtViewerDisplayClass, display_desktop_resize), - NULL, - NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - g_type_class_add_private(class, sizeof(VirtViewerDisplayPrivate)); + widget_class->size_allocate = virt_viewer_display_size_allocate; + widget_class->grab_focus = virt_viewer_display_grab_focus; + + g_object_class_install_property(object_class, + PROP_DESKTOP_WIDTH, + g_param_spec_int("desktop-width", + "Width", + "Desktop width", + 100, + G_MAXINT32, + 100, + G_PARAM_READWRITE)); + + g_object_class_install_property(object_class, + PROP_DESKTOP_HEIGHT, + g_param_spec_int("desktop-height", + "Height", + "Desktop height", + 100, + G_MAXINT32, + 100, + G_PARAM_READWRITE)); + + g_object_class_install_property(object_class, + PROP_ZOOM, + g_param_spec_boolean("zoom", + "Zoom", + "Zoom", + TRUE, + G_PARAM_READWRITE)); + + g_object_class_install_property(object_class, + PROP_ZOOM_LEVEL, + g_param_spec_int("zoom-level", + "Zoom", + "Zoom level", + 10, + 400, + 100, + G_PARAM_READWRITE)); + + g_object_class_install_property(object_class, + PROP_NTH_DISPLAY, + g_param_spec_int("nth-display", + "Nth display", + "Nth display", + 0, + G_MAXINT32, + 0, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property(object_class, + PROP_SHOW_HINT, + g_param_spec_int("show-hint", + "Show hint", + "Show state hint", + 0, + G_MAXINT32, + 0, + G_PARAM_READABLE)); + + + g_signal_new("display-pointer-grab", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, + G_STRUCT_OFFSET(VirtViewerDisplayClass, display_pointer_grab), + NULL, + NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + + g_signal_new("display-pointer-ungrab", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, + G_STRUCT_OFFSET(VirtViewerDisplayClass, display_pointer_ungrab), + NULL, + NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + + g_signal_new("display-keyboard-grab", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, + G_STRUCT_OFFSET(VirtViewerDisplayClass, display_keyboard_grab), + NULL, + NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + + g_signal_new("display-keyboard-ungrab", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, + G_STRUCT_OFFSET(VirtViewerDisplayClass, display_keyboard_ungrab), + NULL, + NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + + g_signal_new("display-desktop-resize", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, + G_STRUCT_OFFSET(VirtViewerDisplayClass, display_desktop_resize), + NULL, + NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + + g_type_class_add_private(class, sizeof(VirtViewerDisplayPrivate)); } static void virt_viewer_display_init(VirtViewerDisplay *display) { - gtk_widget_set_has_window(GTK_WIDGET(display), FALSE); - gtk_widget_set_redraw_on_allocate(GTK_WIDGET(display), FALSE); + gtk_widget_set_has_window(GTK_WIDGET(display), FALSE); + gtk_widget_set_redraw_on_allocate(GTK_WIDGET(display), FALSE); - display->priv = VIRT_VIEWER_DISPLAY_GET_PRIVATE(display); + display->priv = VIRT_VIEWER_DISPLAY_GET_PRIVATE(display); - display->priv->desktopWidth = 100; - display->priv->desktopHeight = 100; - display->priv->zoom_level = 100; - display->priv->zoom = TRUE; - display->priv->dirty = TRUE; - display->priv->maintain_aspect_ratio = TRUE; + display->priv->desktopWidth = 100; + display->priv->desktopHeight = 100; + display->priv->zoom_level = 100; + display->priv->zoom = TRUE; + display->priv->dirty = TRUE; + display->priv->maintain_aspect_ratio = TRUE; } GtkWidget* virt_viewer_display_new(void) { - return g_object_new(VIRT_VIEWER_TYPE_DISPLAY, NULL); + return g_object_new(VIRT_VIEWER_TYPE_DISPLAY, NULL); } static void virt_viewer_display_set_property(GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - VirtViewerDisplay *display = VIRT_VIEWER_DISPLAY(object); - VirtViewerDisplayPrivate *priv = display->priv; - - switch (prop_id) { - case PROP_DESKTOP_WIDTH: - virt_viewer_display_set_desktop_size(display, - g_value_get_int(value), - priv->desktopHeight); - break; - case PROP_DESKTOP_HEIGHT: - virt_viewer_display_set_desktop_size(display, - priv->desktopWidth, - g_value_get_int(value)); - break; - case PROP_NTH_DISPLAY: - priv->nth_display = g_value_get_int(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + VirtViewerDisplay *display = VIRT_VIEWER_DISPLAY(object); + VirtViewerDisplayPrivate *priv = display->priv; + + switch (prop_id) { + case PROP_DESKTOP_WIDTH: + virt_viewer_display_set_desktop_size(display, + g_value_get_int(value), + priv->desktopHeight); + break; + case PROP_DESKTOP_HEIGHT: + virt_viewer_display_set_desktop_size(display, + priv->desktopWidth, + g_value_get_int(value)); + break; + case PROP_NTH_DISPLAY: + priv->nth_display = g_value_get_int(value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void virt_viewer_display_get_property(GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { - VirtViewerDisplay *display = VIRT_VIEWER_DISPLAY(object); - VirtViewerDisplayPrivate *priv = display->priv; - - switch (prop_id) { - case PROP_DESKTOP_WIDTH: - g_value_set_int(value, priv->desktopWidth); - break; - case PROP_DESKTOP_HEIGHT: - g_value_set_int(value, priv->desktopHeight); - break; - case PROP_NTH_DISPLAY: - g_value_set_int(value, priv->nth_display); - break; - case PROP_SHOW_HINT: - g_value_set_int(value, priv->show_hint); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + VirtViewerDisplay *display = VIRT_VIEWER_DISPLAY(object); + VirtViewerDisplayPrivate *priv = display->priv; + + switch (prop_id) { + case PROP_DESKTOP_WIDTH: + g_value_set_int(value, priv->desktopWidth); + break; + case PROP_DESKTOP_HEIGHT: + g_value_set_int(value, priv->desktopHeight); + break; + case PROP_NTH_DISPLAY: + g_value_set_int(value, priv->nth_display); + break; + case PROP_SHOW_HINT: + g_value_set_int(value, priv->show_hint); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void virt_viewer_display_grab_focus(GtkWidget *widget) { - GtkBin *bin = GTK_BIN(widget); + GtkBin *bin = GTK_BIN(widget); - gtk_widget_grab_focus(gtk_bin_get_child(bin)); + gtk_widget_grab_focus(gtk_bin_get_child(bin)); } static gboolean virt_viewer_display_idle(gpointer opaque) { - VirtViewerDisplay *display = opaque; - VirtViewerDisplayPrivate *priv = display->priv; - if (!priv->dirty) - gtk_widget_queue_resize_no_redraw(GTK_WIDGET(display)); - return FALSE; + VirtViewerDisplay *display = opaque; + VirtViewerDisplayPrivate *priv = display->priv; + if (!priv->dirty) + gtk_widget_queue_resize_no_redraw(GTK_WIDGET(display)); + return FALSE; } static void virt_viewer_display_size_request(GtkWidget *widget, - GtkRequisition *requisition) + GtkRequisition *requisition) { - VirtViewerDisplay *display = VIRT_VIEWER_DISPLAY(widget); - VirtViewerDisplayPrivate *priv = display->priv; - int border_width = gtk_container_get_border_width(GTK_CONTAINER(widget)); - - requisition->width = border_width * 2; - requisition->height = border_width * 2; - - if (priv->dirty) { - if (priv->zoom) - requisition->width += priv->desktopWidth * priv->zoom_level / 100; - else - requisition->width += priv->desktopWidth; - } else { - requisition->width += 50; - } - if (priv->dirty) { - if (priv->zoom) - requisition->height += priv->desktopHeight * priv->zoom_level / 100; - else - requisition->height += priv->desktopHeight; - } else { - requisition->height += 50; - } - - DEBUG_LOG("Display size request %dx%d (desktop %dx%d)", - requisition->width, requisition->height, - priv->desktopWidth, priv->desktopHeight); + VirtViewerDisplay *display = VIRT_VIEWER_DISPLAY(widget); + VirtViewerDisplayPrivate *priv = display->priv; + int border_width = gtk_container_get_border_width(GTK_CONTAINER(widget)); + + requisition->width = border_width * 2; + requisition->height = border_width * 2; + + if (priv->dirty) { + if (priv->zoom) + requisition->width += priv->desktopWidth * priv->zoom_level / 100; + else + requisition->width += priv->desktopWidth; + } else { + requisition->width += 50; + } + if (priv->dirty) { + if (priv->zoom) + requisition->height += priv->desktopHeight * priv->zoom_level / 100; + else + requisition->height += priv->desktopHeight; + } else { + requisition->height += 50; + } + + DEBUG_LOG("Display size request %dx%d (desktop %dx%d)", + requisition->width, requisition->height, + priv->desktopWidth, priv->desktopHeight); } #if GTK_CHECK_VERSION(3, 0, 0) static void virt_viewer_display_get_preferred_width(GtkWidget *widget, - int *minwidth, - int *defwidth) + int *minwidth, + int *defwidth) { - GtkRequisition req; + GtkRequisition req; - virt_viewer_display_size_request(widget, &req); + virt_viewer_display_size_request(widget, &req); - *minwidth = *defwidth = req.width; + *minwidth = *defwidth = req.width; } static void virt_viewer_display_get_preferred_height(GtkWidget *widget, - int *minheight, - int *defheight) + int *minheight, + int *defheight) { - GtkRequisition req; + GtkRequisition req; - virt_viewer_display_size_request(widget, &req); + virt_viewer_display_size_request(widget, &req); - *minheight = *defheight = req.height; + *minheight = *defheight = req.height; } #endif static void virt_viewer_display_size_allocate(GtkWidget *widget, - GtkAllocation *allocation) + GtkAllocation *allocation) { - GtkBin *bin = GTK_BIN(widget); - VirtViewerDisplay *display = VIRT_VIEWER_DISPLAY(widget); - VirtViewerDisplayPrivate *priv = display->priv; - GtkAllocation child_allocation; - gint width, height; - gint border_width; - double desktopAspect; - double actualAspect; - GtkWidget *child = gtk_bin_get_child(bin); - - DEBUG_LOG("Allocated %dx%d", allocation->width, allocation->height); - gtk_widget_set_allocation(widget, allocation); - - desktopAspect = (double)priv->desktopWidth / (double)priv->desktopHeight; - - if (child && - gtk_widget_get_visible(child)) { - if (!priv->maintain_aspect_ratio) { - gtk_widget_size_allocate(child, allocation); - goto end; - } - - border_width = gtk_container_get_border_width(GTK_CONTAINER(display)); - - width = MAX(1, allocation->width - 2 * border_width); - height = MAX(1, allocation->height - 2 * border_width); - actualAspect = (double)width / (double)height; - - if (actualAspect > desktopAspect) { - child_allocation.width = height * desktopAspect; - child_allocation.height = height; - } else { - child_allocation.width = width; - child_allocation.height = width / desktopAspect; - } - - child_allocation.x = 0.5 * (width - child_allocation.width) + allocation->x + border_width; - child_allocation.y = 0.5 * (height - child_allocation.height) + allocation->y + border_width; - - DEBUG_LOG("Child allocate %dx%d", child_allocation.width, child_allocation.height); - gtk_widget_size_allocate(child, &child_allocation); - } - -end: - /* This unsets the size request, so that the user can - * manually resize the window smaller again - */ - if (priv->dirty) { - g_idle_add(virt_viewer_display_idle, widget); - priv->dirty = FALSE; - } + GtkBin *bin = GTK_BIN(widget); + VirtViewerDisplay *display = VIRT_VIEWER_DISPLAY(widget); + VirtViewerDisplayPrivate *priv = display->priv; + GtkAllocation child_allocation; + gint width, height; + gint border_width; + double desktopAspect; + double actualAspect; + GtkWidget *child = gtk_bin_get_child(bin); + + DEBUG_LOG("Allocated %dx%d", allocation->width, allocation->height); + gtk_widget_set_allocation(widget, allocation); + + desktopAspect = (double)priv->desktopWidth / (double)priv->desktopHeight; + + if (child && + gtk_widget_get_visible(child)) { + if (!priv->maintain_aspect_ratio) { + gtk_widget_size_allocate(child, allocation); + goto end; + } + + border_width = gtk_container_get_border_width(GTK_CONTAINER(display)); + + width = MAX(1, allocation->width - 2 * border_width); + height = MAX(1, allocation->height - 2 * border_width); + actualAspect = (double)width / (double)height; + + if (actualAspect > desktopAspect) { + child_allocation.width = height * desktopAspect; + child_allocation.height = height; + } else { + child_allocation.width = width; + child_allocation.height = width / desktopAspect; + } + + child_allocation.x = 0.5 * (width - child_allocation.width) + allocation->x + border_width; + child_allocation.y = 0.5 * (height - child_allocation.height) + allocation->y + border_width; + + DEBUG_LOG("Child allocate %dx%d", child_allocation.width, child_allocation.height); + gtk_widget_size_allocate(child, &child_allocation); + } + + end: + /* This unsets the size request, so that the user can + * manually resize the window smaller again + */ + if (priv->dirty) { + g_idle_add(virt_viewer_display_idle, widget); + priv->dirty = FALSE; + } } void virt_viewer_display_set_maintain_aspect_ratio(VirtViewerDisplay *display, - gboolean maintain) + gboolean maintain) { - g_return_if_fail(VIRT_VIEWER_IS_DISPLAY(display)); + g_return_if_fail(VIRT_VIEWER_IS_DISPLAY(display)); - display->priv->maintain_aspect_ratio = maintain; + display->priv->maintain_aspect_ratio = maintain; } void virt_viewer_display_set_desktop_size(VirtViewerDisplay *display, - guint width, - guint height) + guint width, + guint height) { - VirtViewerDisplayPrivate *priv = display->priv; + VirtViewerDisplayPrivate *priv = display->priv; - if (width == priv->desktopWidth && height == priv->desktopHeight) - return; + if (width == priv->desktopWidth && height == priv->desktopHeight) + return; - priv->desktopWidth = width; - priv->desktopHeight = height; - priv->dirty = TRUE; + priv->desktopWidth = width; + priv->desktopHeight = height; + priv->dirty = TRUE; - gtk_widget_queue_resize(GTK_WIDGET(display)); - g_signal_emit_by_name(display, "display-desktop-resize"); + gtk_widget_queue_resize(GTK_WIDGET(display)); + g_signal_emit_by_name(display, "display-desktop-resize"); } void virt_viewer_display_get_desktop_size(VirtViewerDisplay *display, - guint *width, - guint *height) + guint *width, + guint *height) { - VirtViewerDisplayPrivate *priv = display->priv; + VirtViewerDisplayPrivate *priv = display->priv; - *width = priv->desktopWidth; - *height = priv->desktopHeight; + *width = priv->desktopWidth; + *height = priv->desktopHeight; } void virt_viewer_display_set_zoom_level(VirtViewerDisplay *display, - guint zoom) + guint zoom) { - VirtViewerDisplayPrivate *priv = display->priv; - GtkWidget *child = gtk_bin_get_child(GTK_BIN(display)); - - if (zoom < 10) - zoom = 10; - if (zoom > 400) - zoom = 400; - priv->zoom_level = zoom; - - if (child && gtk_widget_get_visible(child)) { - priv->dirty = TRUE; - gtk_widget_queue_resize(GTK_WIDGET(display)); - } + VirtViewerDisplayPrivate *priv = display->priv; + GtkWidget *child = gtk_bin_get_child(GTK_BIN(display)); + + if (zoom < 10) + zoom = 10; + if (zoom > 400) + zoom = 400; + priv->zoom_level = zoom; + + if (child && gtk_widget_get_visible(child)) { + priv->dirty = TRUE; + gtk_widget_queue_resize(GTK_WIDGET(display)); + } } void virt_viewer_display_set_zoom(VirtViewerDisplay *display, - gboolean zoom) + gboolean zoom) { - VirtViewerDisplayPrivate *priv = display->priv; - GtkWidget *child = gtk_bin_get_child(GTK_BIN(display)); - - priv->zoom = zoom; - if (child && gtk_widget_get_visible(child)) { - priv->dirty = TRUE; - gtk_widget_queue_resize(GTK_WIDGET(display)); - } + VirtViewerDisplayPrivate *priv = display->priv; + GtkWidget *child = gtk_bin_get_child(GTK_BIN(display)); + + priv->zoom = zoom; + if (child && gtk_widget_get_visible(child)) { + priv->dirty = TRUE; + gtk_widget_queue_resize(GTK_WIDGET(display)); + } } void virt_viewer_display_send_keys(VirtViewerDisplay *display, - const guint *keyvals, int nkeyvals) + const guint *keyvals, int nkeyvals) { - g_return_if_fail(VIRT_VIEWER_IS_DISPLAY(display)); + g_return_if_fail(VIRT_VIEWER_IS_DISPLAY(display)); - VIRT_VIEWER_DISPLAY_GET_CLASS(display)->send_keys(display, keyvals, nkeyvals); + VIRT_VIEWER_DISPLAY_GET_CLASS(display)->send_keys(display, keyvals, nkeyvals); } GdkPixbuf* virt_viewer_display_get_pixbuf(VirtViewerDisplay *display) { - g_return_val_if_fail(VIRT_VIEWER_IS_DISPLAY(display), NULL); + g_return_val_if_fail(VIRT_VIEWER_IS_DISPLAY(display), NULL); - return VIRT_VIEWER_DISPLAY_GET_CLASS(display)->get_pixbuf(display); + return VIRT_VIEWER_DISPLAY_GET_CLASS(display)->get_pixbuf(display); } void virt_viewer_display_set_show_hint(VirtViewerDisplay *self, gint hint) { - VirtViewerDisplayPrivate *priv; - g_return_if_fail(VIRT_VIEWER_IS_DISPLAY(self)); + VirtViewerDisplayPrivate *priv; + g_return_if_fail(VIRT_VIEWER_IS_DISPLAY(self)); - priv = self->priv; - if (priv->show_hint == hint) - return; + priv = self->priv; + if (priv->show_hint == hint) + return; - priv->show_hint = hint; - g_object_notify(G_OBJECT(self), "show-hint"); + priv->show_hint = hint; + g_object_notify(G_OBJECT(self), "show-hint"); } /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/virt-viewer-display.h b/src/virt-viewer-display.h index 49365ff..ea82936 100644 --- a/src/virt-viewer-display.h +++ b/src/virt-viewer-display.h @@ -30,20 +30,20 @@ G_BEGIN_DECLS #define VIRT_VIEWER_TYPE_DISPLAY virt_viewer_display_get_type() -#define VIRT_VIEWER_DISPLAY(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIRT_VIEWER_TYPE_DISPLAY, VirtViewerDisplay)) +#define VIRT_VIEWER_DISPLAY(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIRT_VIEWER_TYPE_DISPLAY, VirtViewerDisplay)) -#define VIRT_VIEWER_DISPLAY_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), VIRT_VIEWER_TYPE_DISPLAY, VirtViewerDisplayClass)) +#define VIRT_VIEWER_DISPLAY_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), VIRT_VIEWER_TYPE_DISPLAY, VirtViewerDisplayClass)) #define VIRT_VIEWER_IS_DISPLAY(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIRT_VIEWER_TYPE_DISPLAY)) + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIRT_VIEWER_TYPE_DISPLAY)) #define VIRT_VIEWER_IS_DISPLAY_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), VIRT_VIEWER_TYPE_DISPLAY)) + (G_TYPE_CHECK_CLASS_TYPE ((klass), VIRT_VIEWER_TYPE_DISPLAY)) -#define VIRT_VIEWER_DISPLAY_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), VIRT_VIEWER_TYPE_DISPLAY, VirtViewerDisplayClass)) +#define VIRT_VIEWER_DISPLAY_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), VIRT_VIEWER_TYPE_DISPLAY, VirtViewerDisplayClass)) typedef struct _VirtViewerDisplay VirtViewerDisplay; typedef struct _VirtViewerDisplayClass VirtViewerDisplayClass; @@ -52,32 +52,32 @@ typedef struct _VirtViewerDisplayPrivate VirtViewerDisplayPrivate; typedef struct _VirtViewerDisplayChannel VirtViewerDisplayChannel; enum { - VIRT_VIEWER_DISPLAY_SHOW_HINT_HIDE = 0, - VIRT_VIEWER_DISPLAY_SHOW_HINT_READY, + VIRT_VIEWER_DISPLAY_SHOW_HINT_HIDE = 0, + VIRT_VIEWER_DISPLAY_SHOW_HINT_READY, }; /* perhaps this become an interface, and be pushed in gtkvnc and spice? */ struct _VirtViewerDisplay { - GtkBin parent; + GtkBin parent; - VirtViewerDisplayPrivate *priv; + VirtViewerDisplayPrivate *priv; }; struct _VirtViewerDisplayClass { - GtkBinClass parent_class; + GtkBinClass parent_class; - /* virtual methods */ - void (*send_keys)(VirtViewerDisplay* display, - const guint *keyvals, int nkeyvals); - GdkPixbuf *(*get_pixbuf)(VirtViewerDisplay* display); + /* virtual methods */ + void (*send_keys)(VirtViewerDisplay* display, + const guint *keyvals, int nkeyvals); + GdkPixbuf *(*get_pixbuf)(VirtViewerDisplay* display); - /* signals */ - void (*display_pointer_grab)(VirtViewerDisplay *display); - void (*display_pointer_ungrab)(VirtViewerDisplay *display); - void (*display_keyboard_grab)(VirtViewerDisplay *display); - void (*display_keyboard_ungrab)(VirtViewerDisplay *display); + /* signals */ + void (*display_pointer_grab)(VirtViewerDisplay *display); + void (*display_pointer_ungrab)(VirtViewerDisplay *display); + void (*display_keyboard_grab)(VirtViewerDisplay *display); + void (*display_keyboard_ungrab)(VirtViewerDisplay *display); - void (*display_desktop_resize)(VirtViewerDisplay *display); + void (*display_desktop_resize)(VirtViewerDisplay *display); }; GType virt_viewer_display_get_type(void); @@ -87,20 +87,20 @@ GtkWidget *virt_viewer_display_new(void); void virt_viewer_display_set_maintain_aspect_ratio(VirtViewerDisplay *display, gboolean maintain); void virt_viewer_display_set_desktop_size(VirtViewerDisplay *display, - guint width, - guint height); + guint width, + guint height); void virt_viewer_display_get_desktop_size(VirtViewerDisplay *display, - guint *width, - guint *height); + guint *width, + guint *height); void virt_viewer_display_set_zoom_level(VirtViewerDisplay *display, - guint zoom); + guint zoom); void virt_viewer_display_set_zoom(VirtViewerDisplay *display, - gboolean zoom); + gboolean zoom); void virt_viewer_display_send_keys(VirtViewerDisplay *display, - const guint *keyvals, int nkeyvals); + const guint *keyvals, int nkeyvals); GdkPixbuf* virt_viewer_display_get_pixbuf(VirtViewerDisplay *display); void virt_viewer_display_set_show_hint(VirtViewerDisplay *display, gint hint); @@ -109,8 +109,8 @@ G_END_DECLS #endif /* _VIRT_VIEWER_DISPLAY_H */ /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/virt-viewer-events.c b/src/virt-viewer-events.c index 87df739..c0fa068 100644 --- a/src/virt-viewer-events.c +++ b/src/virt-viewer-events.c @@ -48,8 +48,8 @@ static struct virt_viewer_events_handle **handles = NULL; static gboolean virt_viewer_events_dispatch_handle(GIOChannel *source G_GNUC_UNUSED, - GIOCondition condition, - gpointer opaque) + GIOCondition condition, + gpointer opaque) { struct virt_viewer_events_handle *data = opaque; int events = 0; @@ -73,10 +73,10 @@ virt_viewer_events_dispatch_handle(GIOChannel *source G_GNUC_UNUSED, static int virt_viewer_events_add_handle(int fd, - int events, - virEventHandleCallback cb, - void *opaque, - virFreeCallback ff) + int events, + virEventHandleCallback cb, + void *opaque, + virFreeCallback ff) { struct virt_viewer_events_handle *data; GIOCondition cond = 0; @@ -123,7 +123,7 @@ virt_viewer_events_find_handle(int watch) static void virt_viewer_events_update_handle(int watch, - int events) + int events) { struct virt_viewer_events_handle *data = virt_viewer_events_find_handle(watch); @@ -227,9 +227,9 @@ virt_viewer_events_dispatch_timeout(void *opaque) static int virt_viewer_events_add_timeout(int interval, - virEventTimeoutCallback cb, - void *opaque, - virFreeCallback ff) + virEventTimeoutCallback cb, + void *opaque, + virFreeCallback ff) { struct virt_viewer_events_timeout *data; @@ -269,7 +269,7 @@ virt_viewer_events_find_timeout(int timer) static void virt_viewer_events_update_timeout(int timer, - int interval) + int interval) { struct virt_viewer_events_timeout *data = virt_viewer_events_find_timeout(timer); @@ -346,3 +346,10 @@ void virt_viewer_events_register(void) { virt_viewer_events_remove_timeout); } +/* + * Local variables: + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/src/virt-viewer-events.h b/src/virt-viewer-events.h index 44ff8d7..09653cd 100644 --- a/src/virt-viewer-events.h +++ b/src/virt-viewer-events.h @@ -28,3 +28,10 @@ void virt_viewer_events_register(void); #endif +/* + * Local variables: + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/src/virt-viewer-main.c b/src/virt-viewer-main.c index bb967bb..99b4d6f 100644 --- a/src/virt-viewer-main.c +++ b/src/virt-viewer-main.c @@ -35,121 +35,120 @@ static void virt_viewer_version(void) { - g_print(_("%s version %s\n"), PACKAGE, VERSION); + g_print(_("%s version %s\n"), PACKAGE, VERSION); - exit(0); + exit(0); } int main(int argc, char **argv) { - GOptionContext *context; - GError *error = NULL; - int ret = 1; - char *uri = NULL; - int zoom = 100; - gchar **args = NULL; - gboolean verbose = FALSE; - gboolean debug = FALSE; - gboolean direct = FALSE; - gboolean attach = FALSE; - gboolean waitvm = FALSE; - gboolean reconnect = FALSE; - gboolean fullscreen = FALSE; - VirtViewer *viewer = NULL; - const char *help_msg = N_("Run '" PACKAGE " --help' to see a full list of available command line options"); - const GOptionEntry options [] = { - { "version", 'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, - virt_viewer_version, N_("Display version information"), NULL }, - { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, - N_("Display verbose information"), NULL }, - { "direct", 'd', 0, G_OPTION_ARG_NONE, &direct, - N_("Direct connection with no automatic tunnels"), NULL }, - { "attach", 'a', 0, G_OPTION_ARG_NONE, &attach, - N_("Attach to the local display using libvirt"), NULL }, - { "connect", 'c', 0, G_OPTION_ARG_STRING, &uri, - N_("Connect to hypervisor"), "URI"}, - { "wait", 'w', 0, G_OPTION_ARG_NONE, &waitvm, - N_("Wait for domain to start"), NULL }, - { "reconnect", 'r', 0, G_OPTION_ARG_NONE, &reconnect, - N_("Reconnect to domain upon restart"), NULL }, - { "zoom", 'z', 0, G_OPTION_ARG_INT, &zoom, - N_("Zoom level of window, in percentage"), "ZOOM" }, - { "debug", '\0', 0, G_OPTION_ARG_NONE, &debug, - N_("Display debugging information"), NULL }, - { "full-screen", 'f', 0, G_OPTION_ARG_NONE, &fullscreen, - N_("Open in full screen mode"), NULL }, - { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &args, - NULL, "DOMAIN-NAME|ID|UUID" }, - { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } - }; - - setlocale(LC_ALL, ""); - bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR); - bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); - textdomain(GETTEXT_PACKAGE); - - g_set_application_name(_("Virt Viewer")); - - /* Setup command line options */ - context = g_option_context_new (_("- Virtual machine graphical console")); - g_option_context_add_main_entries (context, options, NULL); - g_option_context_add_group (context, gtk_get_option_group (TRUE)); + GOptionContext *context; + GError *error = NULL; + int ret = 1; + char *uri = NULL; + int zoom = 100; + gchar **args = NULL; + gboolean verbose = FALSE; + gboolean debug = FALSE; + gboolean direct = FALSE; + gboolean attach = FALSE; + gboolean waitvm = FALSE; + gboolean reconnect = FALSE; + gboolean fullscreen = FALSE; + VirtViewer *viewer = NULL; + const char *help_msg = N_("Run '" PACKAGE " --help' to see a full list of available command line options"); + const GOptionEntry options [] = { + { "version", 'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, + virt_viewer_version, N_("Display version information"), NULL }, + { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, + N_("Display verbose information"), NULL }, + { "direct", 'd', 0, G_OPTION_ARG_NONE, &direct, + N_("Direct connection with no automatic tunnels"), NULL }, + { "attach", 'a', 0, G_OPTION_ARG_NONE, &attach, + N_("Attach to the local display using libvirt"), NULL }, + { "connect", 'c', 0, G_OPTION_ARG_STRING, &uri, + N_("Connect to hypervisor"), "URI"}, + { "wait", 'w', 0, G_OPTION_ARG_NONE, &waitvm, + N_("Wait for domain to start"), NULL }, + { "reconnect", 'r', 0, G_OPTION_ARG_NONE, &reconnect, + N_("Reconnect to domain upon restart"), NULL }, + { "zoom", 'z', 0, G_OPTION_ARG_INT, &zoom, + N_("Zoom level of window, in percentage"), "ZOOM" }, + { "debug", '\0', 0, G_OPTION_ARG_NONE, &debug, + N_("Display debugging information"), NULL }, + { "full-screen", 'f', 0, G_OPTION_ARG_NONE, &fullscreen, + N_("Open in full screen mode"), NULL }, + { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &args, + NULL, "DOMAIN-NAME|ID|UUID" }, + { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } + }; + + setlocale(LC_ALL, ""); + bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR); + bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); + textdomain(GETTEXT_PACKAGE); + + g_set_application_name(_("Virt Viewer")); + + /* Setup command line options */ + context = g_option_context_new (_("- Virtual machine graphical console")); + g_option_context_add_main_entries (context, options, NULL); + g_option_context_add_group (context, gtk_get_option_group (TRUE)); #ifdef HAVE_GTK_VNC - g_option_context_add_group (context, vnc_display_get_option_group ()); + g_option_context_add_group (context, vnc_display_get_option_group ()); #endif #ifdef HAVE_SPICE_GTK - g_option_context_add_group (context, spice_get_option_group ()); + g_option_context_add_group (context, spice_get_option_group ()); #endif - g_option_context_parse (context, &argc, &argv, &error); - if (error) { - g_printerr("%s\n%s\n", - error->message, - gettext(help_msg)); - g_error_free(error); - goto cleanup; - } + g_option_context_parse (context, &argc, &argv, &error); + if (error) { + g_printerr("%s\n%s\n", + error->message, + gettext(help_msg)); + g_error_free(error); + goto cleanup; + } - g_option_context_free(context); + g_option_context_free(context); - if (!args || (g_strv_length(args) != 1)) { - g_printerr(_("\nUsage: %s [OPTIONS] DOMAIN-NAME|ID|UUID\n\n%s\n\n"), argv[0], help_msg); - goto cleanup; - } + if (!args || (g_strv_length(args) != 1)) { + g_printerr(_("\nUsage: %s [OPTIONS] DOMAIN-NAME|ID|UUID\n\n%s\n\n"), argv[0], help_msg); + goto cleanup; + } - if (zoom < 10 || zoom > 200) { - g_printerr(_("Zoom level must be within 10-200\n")); - goto cleanup; - } + if (zoom < 10 || zoom > 200) { + g_printerr(_("Zoom level must be within 10-200\n")); + goto cleanup; + } - virt_viewer_app_set_debug(debug); + virt_viewer_app_set_debug(debug); - viewer = virt_viewer_new(uri, args[0], zoom, direct, attach, waitvm, reconnect, verbose, NULL); - if (viewer == NULL) - goto cleanup; + viewer = virt_viewer_new(uri, args[0], zoom, direct, attach, waitvm, reconnect, verbose, NULL); + if (viewer == NULL) + goto cleanup; - g_object_set(viewer, "fullscreen", fullscreen, NULL); - if (!virt_viewer_app_start(VIRT_VIEWER_APP(viewer))) - goto cleanup; + g_object_set(viewer, "fullscreen", fullscreen, NULL); + if (!virt_viewer_app_start(VIRT_VIEWER_APP(viewer))) + goto cleanup; - gtk_main(); + gtk_main(); - ret = 0; + ret = 0; -cleanup: - if (viewer) - g_object_unref(viewer); - g_free(uri); - g_strfreev(args); + cleanup: + if (viewer) + g_object_unref(viewer); + g_free(uri); + g_strfreev(args); - return ret; + return ret; } /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 - * indent-tabs-mode: t + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/virt-viewer-notebook.c b/src/virt-viewer-notebook.c index b4e09ec..f1a5b5c 100644 --- a/src/virt-viewer-notebook.c +++ b/src/virt-viewer-notebook.c @@ -26,124 +26,123 @@ G_DEFINE_TYPE (VirtViewerNotebook, virt_viewer_notebook, GTK_TYPE_NOTEBOOK) -#define GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), VIRT_VIEWER_TYPE_NOTEBOOK, VirtViewerNotebookPrivate)) +#define GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), VIRT_VIEWER_TYPE_NOTEBOOK, VirtViewerNotebookPrivate)) struct _VirtViewerNotebookPrivate { - GtkWidget *status; + GtkWidget *status; }; static void virt_viewer_notebook_get_property (GObject *object, guint property_id, - GValue *value G_GNUC_UNUSED, GParamSpec *pspec) + GValue *value G_GNUC_UNUSED, GParamSpec *pspec) { - switch (property_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } + switch (property_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } } static void virt_viewer_notebook_set_property (GObject *object, guint property_id, - const GValue *value G_GNUC_UNUSED, GParamSpec *pspec) + const GValue *value G_GNUC_UNUSED, GParamSpec *pspec) { - switch (property_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } + switch (property_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } } static void virt_viewer_notebook_dispose (GObject *object) { - G_OBJECT_CLASS (virt_viewer_notebook_parent_class)->dispose (object); + G_OBJECT_CLASS (virt_viewer_notebook_parent_class)->dispose (object); } static void virt_viewer_notebook_class_init (VirtViewerNotebookClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - g_type_class_add_private (klass, sizeof (VirtViewerNotebookPrivate)); + g_type_class_add_private (klass, sizeof (VirtViewerNotebookPrivate)); - object_class->get_property = virt_viewer_notebook_get_property; - object_class->set_property = virt_viewer_notebook_set_property; - object_class->dispose = virt_viewer_notebook_dispose; + object_class->get_property = virt_viewer_notebook_get_property; + object_class->set_property = virt_viewer_notebook_set_property; + object_class->dispose = virt_viewer_notebook_dispose; } static void virt_viewer_notebook_init (VirtViewerNotebook *self) { - VirtViewerNotebookPrivate *priv; - GdkColor color; - - self->priv = GET_PRIVATE(self); - priv = self->priv; - - priv->status = gtk_label_new(""); - gtk_notebook_set_show_tabs(GTK_NOTEBOOK(self), FALSE); - gtk_notebook_set_show_border(GTK_NOTEBOOK(self), FALSE); - gtk_notebook_append_page(GTK_NOTEBOOK(self), priv->status, NULL); - gdk_color_parse("white", &color); - gtk_widget_modify_fg(priv->status, GTK_STATE_NORMAL, &color); + VirtViewerNotebookPrivate *priv; + GdkColor color; + + self->priv = GET_PRIVATE(self); + priv = self->priv; + + priv->status = gtk_label_new(""); + gtk_notebook_set_show_tabs(GTK_NOTEBOOK(self), FALSE); + gtk_notebook_set_show_border(GTK_NOTEBOOK(self), FALSE); + gtk_notebook_append_page(GTK_NOTEBOOK(self), priv->status, NULL); + gdk_color_parse("white", &color); + gtk_widget_modify_fg(priv->status, GTK_STATE_NORMAL, &color); } void virt_viewer_notebook_show_status_va(VirtViewerNotebook *self, const gchar *fmt, va_list args) { - VirtViewerNotebookPrivate *priv; - gchar *text; - - DEBUG_LOG("notebook show status %p", self); - g_return_if_fail(VIRT_VIEWER_IS_NOTEBOOK(self)); - - text = g_strdup_vprintf(fmt, args); - priv = self->priv; - gtk_label_set_text(GTK_LABEL(priv->status), text); - gtk_notebook_set_current_page(GTK_NOTEBOOK(self), 0); - gtk_widget_show_all(GTK_WIDGET(self)); - g_free(text); + VirtViewerNotebookPrivate *priv; + gchar *text; + + DEBUG_LOG("notebook show status %p", self); + g_return_if_fail(VIRT_VIEWER_IS_NOTEBOOK(self)); + + text = g_strdup_vprintf(fmt, args); + priv = self->priv; + gtk_label_set_text(GTK_LABEL(priv->status), text); + gtk_notebook_set_current_page(GTK_NOTEBOOK(self), 0); + gtk_widget_show_all(GTK_WIDGET(self)); + g_free(text); } void virt_viewer_notebook_show_status(VirtViewerNotebook *self, const gchar *fmt, ...) { - va_list args; + va_list args; - g_return_if_fail(VIRT_VIEWER_IS_NOTEBOOK(self)); + g_return_if_fail(VIRT_VIEWER_IS_NOTEBOOK(self)); - va_start(args, fmt); - virt_viewer_notebook_show_status_va(self, fmt, args); - va_end(args); + va_start(args, fmt); + virt_viewer_notebook_show_status_va(self, fmt, args); + va_end(args); } void virt_viewer_notebook_show_display(VirtViewerNotebook *self) { - GtkWidget *display; + GtkWidget *display; - DEBUG_LOG("notebook show display %p", self); - g_return_if_fail(VIRT_VIEWER_IS_NOTEBOOK(self)); + DEBUG_LOG("notebook show display %p", self); + g_return_if_fail(VIRT_VIEWER_IS_NOTEBOOK(self)); - display = gtk_notebook_get_nth_page(GTK_NOTEBOOK(self), 1); - g_warn_if_fail(display != NULL); - gtk_widget_grab_focus(display); + display = gtk_notebook_get_nth_page(GTK_NOTEBOOK(self), 1); + g_warn_if_fail(display != NULL); + gtk_widget_grab_focus(display); - gtk_notebook_set_current_page(GTK_NOTEBOOK(self), 1); - gtk_widget_show_all(GTK_WIDGET(self)); + gtk_notebook_set_current_page(GTK_NOTEBOOK(self), 1); + gtk_widget_show_all(GTK_WIDGET(self)); } VirtViewerNotebook* virt_viewer_notebook_new (void) { - return g_object_new (VIRT_VIEWER_TYPE_NOTEBOOK, NULL); + return g_object_new (VIRT_VIEWER_TYPE_NOTEBOOK, NULL); } /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 - * indent-tabs-mode: t + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/virt-viewer-notebook.h b/src/virt-viewer-notebook.h index 0d2b0ce..b349f61 100644 --- a/src/virt-viewer-notebook.h +++ b/src/virt-viewer-notebook.h @@ -31,30 +31,30 @@ G_BEGIN_DECLS #define VIRT_VIEWER_TYPE_NOTEBOOK virt_viewer_notebook_get_type() -#define VIRT_VIEWER_NOTEBOOK(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIRT_VIEWER_TYPE_NOTEBOOK, VirtViewerNotebook)) +#define VIRT_VIEWER_NOTEBOOK(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIRT_VIEWER_TYPE_NOTEBOOK, VirtViewerNotebook)) -#define VIRT_VIEWER_NOTEBOOK_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), VIRT_VIEWER_TYPE_NOTEBOOK, VirtViewerNotebookClass)) +#define VIRT_VIEWER_NOTEBOOK_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), VIRT_VIEWER_TYPE_NOTEBOOK, VirtViewerNotebookClass)) -#define VIRT_VIEWER_IS_NOTEBOOK(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIRT_VIEWER_TYPE_NOTEBOOK)) +#define VIRT_VIEWER_IS_NOTEBOOK(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIRT_VIEWER_TYPE_NOTEBOOK)) -#define VIRT_VIEWER_IS_NOTEBOOK_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), VIRT_VIEWER_TYPE_NOTEBOOK)) +#define VIRT_VIEWER_IS_NOTEBOOK_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), VIRT_VIEWER_TYPE_NOTEBOOK)) -#define VIRT_VIEWER_NOTEBOOK_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), VIRT_VIEWER_TYPE_NOTEBOOK, VirtViewerNotebookClass)) +#define VIRT_VIEWER_NOTEBOOK_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), VIRT_VIEWER_TYPE_NOTEBOOK, VirtViewerNotebookClass)) typedef struct _VirtViewerNotebookPrivate VirtViewerNotebookPrivate; typedef struct { - GtkNotebook parent; - VirtViewerNotebookPrivate *priv; + GtkNotebook parent; + VirtViewerNotebookPrivate *priv; } VirtViewerNotebook; typedef struct { - GtkNotebookClass parent_class; + GtkNotebookClass parent_class; } VirtViewerNotebookClass; GType virt_viewer_notebook_get_type (void); @@ -67,12 +67,10 @@ void virt_viewer_notebook_show_display(VirtViewerNotebook *nb); G_END_DECLS #endif /* _VIRT_VIEWER_NOTEBOOK */ - /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 - * indent-tabs-mode: t + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/virt-viewer-session-spice.c b/src/virt-viewer-session-spice.c index a39ea07..709f3ed 100644 --- a/src/virt-viewer-session-spice.c +++ b/src/virt-viewer-session-spice.c @@ -36,16 +36,16 @@ G_DEFINE_TYPE (VirtViewerSessionSpice, virt_viewer_session_spice, VIRT_VIEWER_TY struct _VirtViewerSessionSpicePrivate { - SpiceSession *session; - SpiceGtkSession *gtk_session; - SpiceAudio *audio; + SpiceSession *session; + SpiceGtkSession *gtk_session; + SpiceAudio *audio; }; #define VIRT_VIEWER_SESSION_SPICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), VIRT_VIEWER_TYPE_SESSION_SPICE, VirtViewerSessionSpicePrivate)) enum { - PROP_0, - PROP_SPICE_SESSION, + PROP_0, + PROP_SPICE_SESSION, }; @@ -57,391 +57,390 @@ static gboolean virt_viewer_session_spice_channel_open_fd(VirtViewerSession *ses static gboolean virt_viewer_session_spice_has_usb(VirtViewerSession *session); static void virt_viewer_session_spice_usb_device_selection(VirtViewerSession *session, GtkWindow *parent); static void virt_viewer_session_spice_channel_new(SpiceSession *s, - SpiceChannel *channel, - VirtViewerSession *session); + SpiceChannel *channel, + VirtViewerSession *session); static void virt_viewer_session_spice_channel_destroy(SpiceSession *s, - SpiceChannel *channel, - VirtViewerSession *session); + SpiceChannel *channel, + VirtViewerSession *session); static void virt_viewer_session_spice_get_property(GObject *object, guint property_id, - GValue *value, GParamSpec *pspec) + GValue *value, GParamSpec *pspec) { - VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(object); - VirtViewerSessionSpicePrivate *priv = self->priv; - - switch (property_id) { - case PROP_SPICE_SESSION: - g_value_set_object(value, priv->session); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } + VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(object); + VirtViewerSessionSpicePrivate *priv = self->priv; + + switch (property_id) { + case PROP_SPICE_SESSION: + g_value_set_object(value, priv->session); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } } static void virt_viewer_session_spice_set_property(GObject *object, guint property_id, - const GValue *value G_GNUC_UNUSED, GParamSpec *pspec) + const GValue *value G_GNUC_UNUSED, GParamSpec *pspec) { - switch (property_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } + switch (property_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } } static void virt_viewer_session_spice_dispose(GObject *obj) { - VirtViewerSessionSpice *spice = VIRT_VIEWER_SESSION_SPICE(obj); + VirtViewerSessionSpice *spice = VIRT_VIEWER_SESSION_SPICE(obj); - if (spice->priv->session) { - spice_session_disconnect(spice->priv->session); - g_object_unref(spice->priv->session); - } - if (spice->priv->audio) - g_object_unref(spice->priv->audio); + if (spice->priv->session) { + spice_session_disconnect(spice->priv->session); + g_object_unref(spice->priv->session); + } + if (spice->priv->audio) + g_object_unref(spice->priv->audio); - G_OBJECT_CLASS(virt_viewer_session_spice_parent_class)->finalize(obj); + G_OBJECT_CLASS(virt_viewer_session_spice_parent_class)->finalize(obj); } static void virt_viewer_session_spice_class_init(VirtViewerSessionSpiceClass *klass) { - VirtViewerSessionClass *dclass = VIRT_VIEWER_SESSION_CLASS(klass); - GObjectClass *oclass = G_OBJECT_CLASS(klass); - - oclass->get_property = virt_viewer_session_spice_get_property; - oclass->set_property = virt_viewer_session_spice_set_property; - oclass->dispose = virt_viewer_session_spice_dispose; - - dclass->close = virt_viewer_session_spice_close; - dclass->open_fd = virt_viewer_session_spice_open_fd; - dclass->open_host = virt_viewer_session_spice_open_host; - dclass->open_uri = virt_viewer_session_spice_open_uri; - dclass->channel_open_fd = virt_viewer_session_spice_channel_open_fd; - dclass->has_usb = virt_viewer_session_spice_has_usb; - dclass->usb_device_selection = virt_viewer_session_spice_usb_device_selection; - - g_type_class_add_private(klass, sizeof(VirtViewerSessionSpicePrivate)); - - g_object_class_install_property(oclass, - PROP_SPICE_SESSION, - g_param_spec_object("spice-session", - "Spice session", - "Spice session", - SPICE_TYPE_SESSION, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + VirtViewerSessionClass *dclass = VIRT_VIEWER_SESSION_CLASS(klass); + GObjectClass *oclass = G_OBJECT_CLASS(klass); + + oclass->get_property = virt_viewer_session_spice_get_property; + oclass->set_property = virt_viewer_session_spice_set_property; + oclass->dispose = virt_viewer_session_spice_dispose; + + dclass->close = virt_viewer_session_spice_close; + dclass->open_fd = virt_viewer_session_spice_open_fd; + dclass->open_host = virt_viewer_session_spice_open_host; + dclass->open_uri = virt_viewer_session_spice_open_uri; + dclass->channel_open_fd = virt_viewer_session_spice_channel_open_fd; + dclass->has_usb = virt_viewer_session_spice_has_usb; + dclass->usb_device_selection = virt_viewer_session_spice_usb_device_selection; + + g_type_class_add_private(klass, sizeof(VirtViewerSessionSpicePrivate)); + + g_object_class_install_property(oclass, + PROP_SPICE_SESSION, + g_param_spec_object("spice-session", + "Spice session", + "Spice session", + SPICE_TYPE_SESSION, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); } static void virt_viewer_session_spice_init(VirtViewerSessionSpice *self G_GNUC_UNUSED) { - self->priv = VIRT_VIEWER_SESSION_SPICE_GET_PRIVATE(self); + self->priv = VIRT_VIEWER_SESSION_SPICE_GET_PRIVATE(self); } static void usb_connect_failed(GObject *object G_GNUC_UNUSED, - SpiceUsbDevice *device G_GNUC_UNUSED, - GError *error, VirtViewerSessionSpice *self) + SpiceUsbDevice *device G_GNUC_UNUSED, + GError *error, VirtViewerSessionSpice *self) { - if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - return; + if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + return; - g_signal_emit_by_name(self, "session-usb-failed", error->message); + g_signal_emit_by_name(self, "session-usb-failed", error->message); } static void create_spice_session(VirtViewerSessionSpice *self) { - SpiceUsbDeviceManager *manager; + SpiceUsbDeviceManager *manager; - g_return_if_fail(self != NULL); - g_return_if_fail(self->priv->session == NULL); + g_return_if_fail(self != NULL); + g_return_if_fail(self->priv->session == NULL); - self->priv->session = spice_session_new(); - spice_set_session_option(self->priv->session); + self->priv->session = spice_session_new(); + spice_set_session_option(self->priv->session); - self->priv->gtk_session = spice_gtk_session_get(self->priv->session); - g_object_set(self->priv->gtk_session, "auto-clipboard", TRUE, NULL); + self->priv->gtk_session = spice_gtk_session_get(self->priv->session); + g_object_set(self->priv->gtk_session, "auto-clipboard", TRUE, NULL); - g_signal_connect(self->priv->session, "channel-new", - G_CALLBACK(virt_viewer_session_spice_channel_new), self); - g_signal_connect(self->priv->session, "channel-destroy", - G_CALLBACK(virt_viewer_session_spice_channel_destroy), self); + g_signal_connect(self->priv->session, "channel-new", + G_CALLBACK(virt_viewer_session_spice_channel_new), self); + g_signal_connect(self->priv->session, "channel-destroy", + G_CALLBACK(virt_viewer_session_spice_channel_destroy), self); - manager = spice_usb_device_manager_get(self->priv->session, NULL); - if (manager) - g_signal_connect(manager, "auto-connect-failed", - G_CALLBACK(usb_connect_failed), self); + manager = spice_usb_device_manager_get(self->priv->session, NULL); + if (manager) + g_signal_connect(manager, "auto-connect-failed", + G_CALLBACK(usb_connect_failed), self); - g_object_bind_property(self, "auto-usbredir", - self->priv->gtk_session, "auto-usbredir", - G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); + g_object_bind_property(self, "auto-usbredir", + self->priv->gtk_session, "auto-usbredir", + G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); } static void virt_viewer_session_spice_close(VirtViewerSession *session) { - VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session); + VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session); - g_return_if_fail(self != NULL); + g_return_if_fail(self != NULL); - virt_viewer_session_clear_displays(session); + virt_viewer_session_clear_displays(session); - if (self->priv->session) { - spice_session_disconnect(self->priv->session); - g_object_unref(self->priv->session); - self->priv->session = NULL; - self->priv->gtk_session = NULL; + if (self->priv->session) { + spice_session_disconnect(self->priv->session); + g_object_unref(self->priv->session); + self->priv->session = NULL; + self->priv->gtk_session = NULL; - if (self->priv->audio) - g_object_unref(self->priv->audio); - self->priv->audio = NULL; - } + if (self->priv->audio) + g_object_unref(self->priv->audio); + self->priv->audio = NULL; + } - /* FIXME: version 0.7 of spice-gtk allows reuse of session */ - create_spice_session(self); + /* FIXME: version 0.7 of spice-gtk allows reuse of session */ + create_spice_session(self); } static gboolean virt_viewer_session_spice_open_host(VirtViewerSession *session, - char *host, - char *port) + char *host, + char *port) { - VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session); + VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session); - g_return_val_if_fail(self != NULL, FALSE); - g_return_val_if_fail(self->priv->session != NULL, FALSE); + g_return_val_if_fail(self != NULL, FALSE); + g_return_val_if_fail(self->priv->session != NULL, FALSE); - g_object_set(self->priv->session, - "host", host, - "port", port, - NULL); + g_object_set(self->priv->session, + "host", host, + "port", port, + NULL); - return spice_session_connect(self->priv->session); + return spice_session_connect(self->priv->session); } static gboolean virt_viewer_session_spice_open_uri(VirtViewerSession *session, - char *uri) + char *uri) { - VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session); + VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session); - g_return_val_if_fail(self != NULL, FALSE); - g_return_val_if_fail(self->priv->session != NULL, FALSE); + g_return_val_if_fail(self != NULL, FALSE); + g_return_val_if_fail(self->priv->session != NULL, FALSE); - g_object_set(self->priv->session, "uri", uri, NULL); + g_object_set(self->priv->session, "uri", uri, NULL); - return spice_session_connect(self->priv->session); + return spice_session_connect(self->priv->session); } static gboolean virt_viewer_session_spice_open_fd(VirtViewerSession *session, - int fd) + int fd) { - VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session); + VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session); - g_return_val_if_fail(self != NULL, FALSE); + g_return_val_if_fail(self != NULL, FALSE); - return spice_session_open_fd(self->priv->session, fd); + return spice_session_open_fd(self->priv->session, fd); } static gboolean virt_viewer_session_spice_channel_open_fd(VirtViewerSession *session, - VirtViewerSessionChannel *channel, - int fd) + VirtViewerSessionChannel *channel, + int fd) { - VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session); + VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session); - g_return_val_if_fail(self != NULL, FALSE); + g_return_val_if_fail(self != NULL, FALSE); - return spice_channel_open_fd(SPICE_CHANNEL(channel), fd); + return spice_channel_open_fd(SPICE_CHANNEL(channel), fd); } static void virt_viewer_session_spice_channel_open_fd_request(SpiceChannel *channel, - gint tls G_GNUC_UNUSED, - VirtViewerSession *session) + gint tls G_GNUC_UNUSED, + VirtViewerSession *session) { - g_signal_emit_by_name(session, "session-channel-open", channel); + g_signal_emit_by_name(session, "session-channel-open", channel); } static void virt_viewer_session_spice_main_channel_event(SpiceChannel *channel G_GNUC_UNUSED, - SpiceChannelEvent event, - VirtViewerSession *session) + SpiceChannelEvent event, + VirtViewerSession *session) { - VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session); - char *password = NULL; - - g_return_if_fail(self != NULL); - - switch (event) { - case SPICE_CHANNEL_OPENED: - DEBUG_LOG("main channel: opened"); - break; - case SPICE_CHANNEL_CLOSED: - DEBUG_LOG("main channel: closed"); - g_signal_emit_by_name(session, "session-disconnected"); - break; - case SPICE_CHANNEL_ERROR_CONNECT: - DEBUG_LOG("main channel: failed to connect"); - g_signal_emit_by_name(session, "session-disconnected"); - break; - case SPICE_CHANNEL_ERROR_AUTH: - DEBUG_LOG("main channel: auth failure (wrong password?)"); - int ret = virt_viewer_auth_collect_credentials("SPICE", - NULL, - NULL, &password); - if (ret < 0) { - g_signal_emit_by_name(session, "session-cancelled"); - } else { - g_object_set(self->priv->session, "password", password, NULL); - spice_session_connect(self->priv->session); - } - break; - default: - g_message("unhandled spice main channel event: %d", event); - g_signal_emit_by_name(session, "session-disconnected"); - break; - } - - g_free(password); + VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session); + char *password = NULL; + + g_return_if_fail(self != NULL); + + switch (event) { + case SPICE_CHANNEL_OPENED: + DEBUG_LOG("main channel: opened"); + break; + case SPICE_CHANNEL_CLOSED: + DEBUG_LOG("main channel: closed"); + g_signal_emit_by_name(session, "session-disconnected"); + break; + case SPICE_CHANNEL_ERROR_CONNECT: + DEBUG_LOG("main channel: failed to connect"); + g_signal_emit_by_name(session, "session-disconnected"); + break; + case SPICE_CHANNEL_ERROR_AUTH: + DEBUG_LOG("main channel: auth failure (wrong password?)"); + int ret = virt_viewer_auth_collect_credentials("SPICE", + NULL, + NULL, &password); + if (ret < 0) { + g_signal_emit_by_name(session, "session-cancelled"); + } else { + g_object_set(self->priv->session, "password", password, NULL); + spice_session_connect(self->priv->session); + } + break; + default: + g_message("unhandled spice main channel event: %d", event); + g_signal_emit_by_name(session, "session-disconnected"); + break; + } + + g_free(password); } static gboolean virt_viewer_session_spice_has_usb(VirtViewerSession *session) { - VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session); - VirtViewerSessionSpicePrivate *priv = self->priv; + VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session); + VirtViewerSessionSpicePrivate *priv = self->priv; - return spice_usb_device_manager_get(priv->session, NULL) && - spice_session_has_channel_type(priv->session, - SPICE_CHANNEL_USBREDIR); + return spice_usb_device_manager_get(priv->session, NULL) && + spice_session_has_channel_type(priv->session, + SPICE_CHANNEL_USBREDIR); } static void virt_viewer_session_spice_usb_device_selection(VirtViewerSession *session, - GtkWindow *parent) + GtkWindow *parent) { - VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session); - VirtViewerSessionSpicePrivate *priv = self->priv; - GtkWidget *dialog, *area, *usb_device_widget; - - /* Create the widgets */ - dialog = gtk_dialog_new_with_buttons( - _("Select USB devices for redirection"), parent, - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, - NULL); - gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); - area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); - - usb_device_widget = spice_usb_device_widget_new(priv->session, - "%s %s"); - g_signal_connect(usb_device_widget, "connect-failed", - G_CALLBACK(usb_connect_failed), self); - gtk_box_pack_start(GTK_BOX(area), usb_device_widget, TRUE, TRUE, 5); - - /* show and run */ - gtk_widget_show_all(dialog); - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); + VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session); + VirtViewerSessionSpicePrivate *priv = self->priv; + GtkWidget *dialog, *area, *usb_device_widget; + + /* Create the widgets */ + dialog = gtk_dialog_new_with_buttons( + _("Select USB devices for redirection"), parent, + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + NULL); + gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); + area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + + usb_device_widget = spice_usb_device_widget_new(priv->session, + "%s %s"); + g_signal_connect(usb_device_widget, "connect-failed", + G_CALLBACK(usb_connect_failed), self); + gtk_box_pack_start(GTK_BOX(area), usb_device_widget, TRUE, TRUE, 5); + + /* show and run */ + gtk_widget_show_all(dialog); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); } static void virt_viewer_session_spice_channel_new(SpiceSession *s, - SpiceChannel *channel, - VirtViewerSession *session) + SpiceChannel *channel, + VirtViewerSession *session) { - VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session); - int id; + VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session); + int id; - g_return_if_fail(self != NULL); + g_return_if_fail(self != NULL); - g_signal_connect(channel, "open-fd", - G_CALLBACK(virt_viewer_session_spice_channel_open_fd_request), self); + g_signal_connect(channel, "open-fd", + G_CALLBACK(virt_viewer_session_spice_channel_open_fd_request), self); - g_object_get(channel, "channel-id", &id, NULL); + g_object_get(channel, "channel-id", &id, NULL); - if (SPICE_IS_MAIN_CHANNEL(channel)) { - g_signal_connect(channel, "channel-event", - G_CALLBACK(virt_viewer_session_spice_main_channel_event), self); - } + if (SPICE_IS_MAIN_CHANNEL(channel)) { + g_signal_connect(channel, "channel-event", + G_CALLBACK(virt_viewer_session_spice_main_channel_event), self); + } - if (SPICE_IS_DISPLAY_CHANNEL(channel)) { - GtkWidget *display; + if (SPICE_IS_DISPLAY_CHANNEL(channel)) { + GtkWidget *display; - g_signal_emit_by_name(session, "session-connected"); + g_signal_emit_by_name(session, "session-connected"); - DEBUG_LOG("new session channel (#%d)", id); - display = virt_viewer_display_spice_new(channel, - spice_display_new(s, id)); + DEBUG_LOG("new session channel (#%d)", id); + display = virt_viewer_display_spice_new(channel, + spice_display_new(s, id)); - virt_viewer_session_add_display(VIRT_VIEWER_SESSION(session), - VIRT_VIEWER_DISPLAY(display)); + virt_viewer_session_add_display(VIRT_VIEWER_SESSION(session), + VIRT_VIEWER_DISPLAY(display)); - g_signal_emit_by_name(session, "session-initialized"); - } + g_signal_emit_by_name(session, "session-initialized"); + } - if (SPICE_IS_INPUTS_CHANNEL(channel)) { - DEBUG_LOG("new inputs channel"); - } + if (SPICE_IS_INPUTS_CHANNEL(channel)) { + DEBUG_LOG("new inputs channel"); + } - if (SPICE_IS_PLAYBACK_CHANNEL(channel)) { - DEBUG_LOG("new audio channel"); - if (self->priv->audio != NULL) - return; - self->priv->audio = spice_audio_new(s, NULL, NULL); - } + if (SPICE_IS_PLAYBACK_CHANNEL(channel)) { + DEBUG_LOG("new audio channel"); + if (self->priv->audio != NULL) + return; + self->priv->audio = spice_audio_new(s, NULL, NULL); + } } static void virt_viewer_session_spice_channel_destroy(G_GNUC_UNUSED SpiceSession *s, - SpiceChannel *channel, - VirtViewerSession *session) + SpiceChannel *channel, + VirtViewerSession *session) { - VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session); - int id; + VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session); + int id; - g_return_if_fail(self != NULL); + g_return_if_fail(self != NULL); - g_object_get(channel, "channel-id", &id, NULL); - if (SPICE_IS_MAIN_CHANNEL(channel)) { - DEBUG_LOG("zap main channel"); - } + g_object_get(channel, "channel-id", &id, NULL); + if (SPICE_IS_MAIN_CHANNEL(channel)) { + DEBUG_LOG("zap main channel"); + } - if (SPICE_IS_DISPLAY_CHANNEL(channel)) { - DEBUG_LOG("zap session channel (#%d)", id); - } + if (SPICE_IS_DISPLAY_CHANNEL(channel)) { + DEBUG_LOG("zap session channel (#%d)", id); + } - if (SPICE_IS_PLAYBACK_CHANNEL(channel) && self->priv->audio) { - DEBUG_LOG("zap audio channel"); - g_object_unref(self->priv->audio); - self->priv->audio = NULL; - } + if (SPICE_IS_PLAYBACK_CHANNEL(channel) && self->priv->audio) { + DEBUG_LOG("zap audio channel"); + g_object_unref(self->priv->audio); + self->priv->audio = NULL; + } } VirtViewerSession * virt_viewer_session_spice_new(void) { - VirtViewerSessionSpice *self; + VirtViewerSessionSpice *self; - self = g_object_new(VIRT_VIEWER_TYPE_SESSION_SPICE, NULL); + self = g_object_new(VIRT_VIEWER_TYPE_SESSION_SPICE, NULL); - create_spice_session(self); + create_spice_session(self); - return VIRT_VIEWER_SESSION(self); + return VIRT_VIEWER_SESSION(self); } /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 - * indent-tabs-mode: t + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/virt-viewer-session-spice.h b/src/virt-viewer-session-spice.h index 8926940..192c549 100644 --- a/src/virt-viewer-session-spice.h +++ b/src/virt-viewer-session-spice.h @@ -34,33 +34,33 @@ G_BEGIN_DECLS #define VIRT_VIEWER_TYPE_SESSION_SPICE virt_viewer_session_spice_get_type() -#define VIRT_VIEWER_SESSION_SPICE(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIRT_VIEWER_TYPE_SESSION_SPICE, VirtViewerSessionSpice)) +#define VIRT_VIEWER_SESSION_SPICE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIRT_VIEWER_TYPE_SESSION_SPICE, VirtViewerSessionSpice)) -#define VIRT_VIEWER_SESSION_SPICE_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), VIRT_VIEWER_TYPE_SESSION_SPICE, VirtViewerSessionSpiceClass)) +#define VIRT_VIEWER_SESSION_SPICE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), VIRT_VIEWER_TYPE_SESSION_SPICE, VirtViewerSessionSpiceClass)) -#define VIRT_VIEWER_IS_SESSION_SPICE(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIRT_VIEWER_TYPE_SESSION_SPICE)) +#define VIRT_VIEWER_IS_SESSION_SPICE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIRT_VIEWER_TYPE_SESSION_SPICE)) -#define VIRT_VIEWER_IS_SESSION_SPICE_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), VIRT_VIEWER_TYPE_SESSION_SPICE)) +#define VIRT_VIEWER_IS_SESSION_SPICE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), VIRT_VIEWER_TYPE_SESSION_SPICE)) -#define VIRT_VIEWER_SESSION_SPICE_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), VIRT_VIEWER_TYPE_SESSION_SPICE, VirtViewerSessionSpiceClass)) +#define VIRT_VIEWER_SESSION_SPICE_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), VIRT_VIEWER_TYPE_SESSION_SPICE, VirtViewerSessionSpiceClass)) typedef struct _VirtViewerSessionSpice VirtViewerSessionSpice; typedef struct _VirtViewerSessionSpiceClass VirtViewerSessionSpiceClass; typedef struct _VirtViewerSessionSpicePrivate VirtViewerSessionSpicePrivate; struct _VirtViewerSessionSpice { - VirtViewerSession parent; + VirtViewerSession parent; - VirtViewerSessionSpicePrivate *priv; + VirtViewerSessionSpicePrivate *priv; }; struct _VirtViewerSessionSpiceClass { - VirtViewerSessionClass parent_class; + VirtViewerSessionClass parent_class; }; GType virt_viewer_session_spice_get_type(void); @@ -70,11 +70,10 @@ VirtViewerSession* virt_viewer_session_spice_new(void); G_END_DECLS #endif /* _VIRT_VIEWER_SESSION_SPICE_H */ - /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/virt-viewer-session-vnc.c b/src/virt-viewer-session-vnc.c index 7f660ea..19116dd 100644 --- a/src/virt-viewer-session-vnc.c +++ b/src/virt-viewer-session-vnc.c @@ -32,8 +32,8 @@ G_DEFINE_TYPE(VirtViewerSessionVnc, virt_viewer_session_vnc, VIRT_VIEWER_TYPE_SESSION) struct _VirtViewerSessionVncPrivate { - /* XXX we should really just have a VncConnection */ - VncDisplay *vnc; + /* XXX we should really just have a VncConnection */ + VncDisplay *vnc; }; #define VIRT_VIEWER_SESSION_VNC_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), VIRT_VIEWER_TYPE_SESSION_VNC, VirtViewerSessionVncPrivate)) @@ -43,243 +43,240 @@ static gboolean virt_viewer_session_vnc_open_fd(VirtViewerSession* session, int static gboolean virt_viewer_session_vnc_open_host(VirtViewerSession* session, char *host, char *port); static gboolean virt_viewer_session_vnc_open_uri(VirtViewerSession* session, char *uri); static gboolean virt_viewer_session_vnc_channel_open_fd(VirtViewerSession* session, - VirtViewerSessionChannel* channel, int fd); + VirtViewerSessionChannel* channel, int fd); static void virt_viewer_session_vnc_finalize(GObject *obj) { - VirtViewerSessionVnc *vnc = VIRT_VIEWER_SESSION_VNC(obj); + VirtViewerSessionVnc *vnc = VIRT_VIEWER_SESSION_VNC(obj); - if (vnc->priv->vnc) { - vnc_display_close(vnc->priv->vnc); - g_object_unref(vnc->priv->vnc); - } + if (vnc->priv->vnc) { + vnc_display_close(vnc->priv->vnc); + g_object_unref(vnc->priv->vnc); + } - G_OBJECT_CLASS(virt_viewer_session_vnc_parent_class)->finalize(obj); + G_OBJECT_CLASS(virt_viewer_session_vnc_parent_class)->finalize(obj); } static void virt_viewer_session_vnc_class_init(VirtViewerSessionVncClass *klass) { - VirtViewerSessionClass *dclass = VIRT_VIEWER_SESSION_CLASS(klass); - GObjectClass *oclass = G_OBJECT_CLASS(klass); + VirtViewerSessionClass *dclass = VIRT_VIEWER_SESSION_CLASS(klass); + GObjectClass *oclass = G_OBJECT_CLASS(klass); - oclass->finalize = virt_viewer_session_vnc_finalize; + oclass->finalize = virt_viewer_session_vnc_finalize; - dclass->close = virt_viewer_session_vnc_close; - dclass->open_fd = virt_viewer_session_vnc_open_fd; - dclass->open_host = virt_viewer_session_vnc_open_host; - dclass->open_uri = virt_viewer_session_vnc_open_uri; - dclass->channel_open_fd = virt_viewer_session_vnc_channel_open_fd; + dclass->close = virt_viewer_session_vnc_close; + dclass->open_fd = virt_viewer_session_vnc_open_fd; + dclass->open_host = virt_viewer_session_vnc_open_host; + dclass->open_uri = virt_viewer_session_vnc_open_uri; + dclass->channel_open_fd = virt_viewer_session_vnc_channel_open_fd; - g_type_class_add_private(klass, sizeof(VirtViewerSessionVncPrivate)); + g_type_class_add_private(klass, sizeof(VirtViewerSessionVncPrivate)); } static void virt_viewer_session_vnc_init(VirtViewerSessionVnc *self G_GNUC_UNUSED) { - self->priv = VIRT_VIEWER_SESSION_VNC_GET_PRIVATE(self); + self->priv = VIRT_VIEWER_SESSION_VNC_GET_PRIVATE(self); } static void virt_viewer_session_vnc_connected(VncDisplay *vnc G_GNUC_UNUSED, - VirtViewerSessionVnc *session) + VirtViewerSessionVnc *session) { - GtkWidget *display = virt_viewer_display_vnc_new(session->priv->vnc); - g_signal_emit_by_name(session, "session-connected"); - virt_viewer_display_set_show_hint(VIRT_VIEWER_DISPLAY(display), - VIRT_VIEWER_DISPLAY_SHOW_HINT_READY); - virt_viewer_session_add_display(VIRT_VIEWER_SESSION(session), - VIRT_VIEWER_DISPLAY(display)); + GtkWidget *display = virt_viewer_display_vnc_new(session->priv->vnc); + g_signal_emit_by_name(session, "session-connected"); + virt_viewer_display_set_show_hint(VIRT_VIEWER_DISPLAY(display), + VIRT_VIEWER_DISPLAY_SHOW_HINT_READY); + virt_viewer_session_add_display(VIRT_VIEWER_SESSION(session), + VIRT_VIEWER_DISPLAY(display)); } static void virt_viewer_session_vnc_disconnected(VncDisplay *vnc G_GNUC_UNUSED, - VirtViewerSessionVnc *session) + VirtViewerSessionVnc *session) { - g_signal_emit_by_name(session, "session-disconnected"); - /* TODO perhaps? */ - /* virt_viewer_display_set_show_hint(VIRT_VIEWER_DISPLAY(session->priv->vnc), */ - /* VIRT_VIEWER_DISPLAY_SHOW_HINT_HIDE); */ + g_signal_emit_by_name(session, "session-disconnected"); + /* TODO perhaps? */ + /* virt_viewer_display_set_show_hint(VIRT_VIEWER_DISPLAY(session->priv->vnc), */ + /* VIRT_VIEWER_DISPLAY_SHOW_HINT_HIDE); */ } static void virt_viewer_session_vnc_initialized(VncDisplay *vnc G_GNUC_UNUSED, - VirtViewerSessionVnc *session) + VirtViewerSessionVnc *session) { - g_signal_emit_by_name(session, "session-initialized"); + g_signal_emit_by_name(session, "session-initialized"); } static void virt_viewer_session_vnc_cut_text(VncDisplay *vnc G_GNUC_UNUSED, - const char *text, - VirtViewerSession *session) + const char *text, + VirtViewerSession *session) { - g_signal_emit_by_name(session, "session-cut-text", text); + g_signal_emit_by_name(session, "session-cut-text", text); } static void virt_viewer_session_vnc_bell(VncDisplay *vnc G_GNUC_UNUSED, - VirtViewerSession *session) + VirtViewerSession *session) { - g_signal_emit_by_name(session, "session-bell"); + g_signal_emit_by_name(session, "session-bell"); } static void virt_viewer_session_vnc_auth_unsupported(VncDisplay *vnc G_GNUC_UNUSED, - unsigned int authType, - VirtViewerSession *session) + unsigned int authType, + VirtViewerSession *session) { - char *msg = g_strdup_printf(_("Unsupported authentication type %d"), - authType); - g_signal_emit_by_name(session, "session-auth-failed", msg); - g_free(msg); + char *msg = g_strdup_printf(_("Unsupported authentication type %d"), + authType); + g_signal_emit_by_name(session, "session-auth-failed", msg); + g_free(msg); } static void virt_viewer_session_vnc_auth_failure(VncDisplay *vnc G_GNUC_UNUSED, - const char *reason, - VirtViewerSession *session) + const char *reason, + VirtViewerSession *session) { - g_signal_emit_by_name(session, "session-auth-refused", reason); + g_signal_emit_by_name(session, "session-auth-refused", reason); } static gboolean virt_viewer_session_vnc_open_fd(VirtViewerSession* session, - int fd) + int fd) { - VirtViewerSessionVnc *self = VIRT_VIEWER_SESSION_VNC(session); + VirtViewerSessionVnc *self = VIRT_VIEWER_SESSION_VNC(session); - g_return_val_if_fail(self != NULL, FALSE); - g_return_val_if_fail(self->priv->vnc != NULL, FALSE); + g_return_val_if_fail(self != NULL, FALSE); + g_return_val_if_fail(self->priv->vnc != NULL, FALSE); - return vnc_display_open_fd(self->priv->vnc, fd); + return vnc_display_open_fd(self->priv->vnc, fd); } static gboolean virt_viewer_session_vnc_channel_open_fd(VirtViewerSession* session G_GNUC_UNUSED, - VirtViewerSessionChannel* channel G_GNUC_UNUSED, - int fd G_GNUC_UNUSED) + VirtViewerSessionChannel* channel G_GNUC_UNUSED, + int fd G_GNUC_UNUSED) { - g_warning("channel_open_fd is not supported by VNC"); - return FALSE; + g_warning("channel_open_fd is not supported by VNC"); + return FALSE; } static gboolean virt_viewer_session_vnc_open_host(VirtViewerSession* session, - char *host, - char *port) + char *host, + char *port) { - VirtViewerSessionVnc *self = VIRT_VIEWER_SESSION_VNC(session); + VirtViewerSessionVnc *self = VIRT_VIEWER_SESSION_VNC(session); - g_return_val_if_fail(self != NULL, FALSE); - g_return_val_if_fail(self->priv->vnc != NULL, FALSE); + g_return_val_if_fail(self != NULL, FALSE); + g_return_val_if_fail(self->priv->vnc != NULL, FALSE); - return vnc_display_open_host(self->priv->vnc, host, port); + return vnc_display_open_host(self->priv->vnc, host, port); } static gboolean virt_viewer_session_vnc_open_uri(VirtViewerSession* session, - char *uristr) + char *uristr) { - VirtViewerSessionVnc *self = VIRT_VIEWER_SESSION_VNC(session); - xmlURIPtr uri = NULL; - gchar *portstr; - gboolean ret; + VirtViewerSessionVnc *self = VIRT_VIEWER_SESSION_VNC(session); + xmlURIPtr uri = NULL; + gchar *portstr; + gboolean ret; - g_return_val_if_fail(self != NULL, FALSE); - g_return_val_if_fail(self->priv->vnc != NULL, FALSE); + g_return_val_if_fail(self != NULL, FALSE); + g_return_val_if_fail(self->priv->vnc != NULL, FALSE); - if (!(uri = xmlParseURI(uristr))) - return FALSE; + if (!(uri = xmlParseURI(uristr))) + return FALSE; - portstr = g_strdup_printf("%d", uri->port); + portstr = g_strdup_printf("%d", uri->port); - ret = vnc_display_open_host(self->priv->vnc, uri->server, portstr); - g_free(portstr); - xmlFreeURI(uri); - return ret; + ret = vnc_display_open_host(self->priv->vnc, uri->server, portstr); + g_free(portstr); + xmlFreeURI(uri); + return ret; } static void virt_viewer_session_vnc_close(VirtViewerSession* session) { - VirtViewerSessionVnc *self = VIRT_VIEWER_SESSION_VNC(session); + VirtViewerSessionVnc *self = VIRT_VIEWER_SESSION_VNC(session); - g_return_if_fail(self != NULL); + g_return_if_fail(self != NULL); - if (self->priv->vnc != NULL) { - virt_viewer_session_clear_displays(session); - vnc_display_close(self->priv->vnc); - g_object_unref(self->priv->vnc); - } + if (self->priv->vnc != NULL) { + virt_viewer_session_clear_displays(session); + vnc_display_close(self->priv->vnc); + g_object_unref(self->priv->vnc); + } - self->priv->vnc = VNC_DISPLAY(vnc_display_new()); + self->priv->vnc = VNC_DISPLAY(vnc_display_new()); - g_signal_connect(self->priv->vnc, "vnc-connected", - G_CALLBACK(virt_viewer_session_vnc_connected), session); - g_signal_connect(self->priv->vnc, "vnc-initialized", - G_CALLBACK(virt_viewer_session_vnc_initialized), session); - g_signal_connect(self->priv->vnc, "vnc-disconnected", - G_CALLBACK(virt_viewer_session_vnc_disconnected), session); + g_signal_connect(self->priv->vnc, "vnc-connected", + G_CALLBACK(virt_viewer_session_vnc_connected), session); + g_signal_connect(self->priv->vnc, "vnc-initialized", + G_CALLBACK(virt_viewer_session_vnc_initialized), session); + g_signal_connect(self->priv->vnc, "vnc-disconnected", + G_CALLBACK(virt_viewer_session_vnc_disconnected), session); - g_signal_connect(self->priv->vnc, "vnc-bell", - G_CALLBACK(virt_viewer_session_vnc_bell), session); - g_signal_connect(self->priv->vnc, "vnc-auth-failure", - G_CALLBACK(virt_viewer_session_vnc_auth_failure), session); - g_signal_connect(self->priv->vnc, "vnc-auth-unsupported", - G_CALLBACK(virt_viewer_session_vnc_auth_unsupported), session); - g_signal_connect(self->priv->vnc, "vnc-server-cut-text", - G_CALLBACK(virt_viewer_session_vnc_cut_text), session); + g_signal_connect(self->priv->vnc, "vnc-bell", + G_CALLBACK(virt_viewer_session_vnc_bell), session); + g_signal_connect(self->priv->vnc, "vnc-auth-failure", + G_CALLBACK(virt_viewer_session_vnc_auth_failure), session); + g_signal_connect(self->priv->vnc, "vnc-auth-unsupported", + G_CALLBACK(virt_viewer_session_vnc_auth_unsupported), session); + g_signal_connect(self->priv->vnc, "vnc-server-cut-text", + G_CALLBACK(virt_viewer_session_vnc_cut_text), session); - g_signal_connect(self->priv->vnc, "vnc-auth-credential", - G_CALLBACK(virt_viewer_auth_vnc_credentials), NULL); + g_signal_connect(self->priv->vnc, "vnc-auth-credential", + G_CALLBACK(virt_viewer_auth_vnc_credentials), NULL); - } +} VirtViewerSession * virt_viewer_session_vnc_new(void) { - VirtViewerSessionVnc *session; + VirtViewerSessionVnc *session; - session = g_object_new(VIRT_VIEWER_TYPE_SESSION_VNC, NULL); + session = g_object_new(VIRT_VIEWER_TYPE_SESSION_VNC, NULL); - session->priv->vnc = VNC_DISPLAY(vnc_display_new()); + session->priv->vnc = VNC_DISPLAY(vnc_display_new()); - g_signal_connect(session->priv->vnc, "vnc-connected", - G_CALLBACK(virt_viewer_session_vnc_connected), session); - g_signal_connect(session->priv->vnc, "vnc-initialized", - G_CALLBACK(virt_viewer_session_vnc_initialized), session); - g_signal_connect(session->priv->vnc, "vnc-disconnected", - G_CALLBACK(virt_viewer_session_vnc_disconnected), session); + g_signal_connect(session->priv->vnc, "vnc-connected", + G_CALLBACK(virt_viewer_session_vnc_connected), session); + g_signal_connect(session->priv->vnc, "vnc-initialized", + G_CALLBACK(virt_viewer_session_vnc_initialized), session); + g_signal_connect(session->priv->vnc, "vnc-disconnected", + G_CALLBACK(virt_viewer_session_vnc_disconnected), session); - g_signal_connect(session->priv->vnc, "vnc-bell", - G_CALLBACK(virt_viewer_session_vnc_bell), session); - g_signal_connect(session->priv->vnc, "vnc-auth-failure", - G_CALLBACK(virt_viewer_session_vnc_auth_failure), session); - g_signal_connect(session->priv->vnc, "vnc-auth-unsupported", - G_CALLBACK(virt_viewer_session_vnc_auth_unsupported), session); - g_signal_connect(session->priv->vnc, "vnc-server-cut-text", - G_CALLBACK(virt_viewer_session_vnc_cut_text), session); + g_signal_connect(session->priv->vnc, "vnc-bell", + G_CALLBACK(virt_viewer_session_vnc_bell), session); + g_signal_connect(session->priv->vnc, "vnc-auth-failure", + G_CALLBACK(virt_viewer_session_vnc_auth_failure), session); + g_signal_connect(session->priv->vnc, "vnc-auth-unsupported", + G_CALLBACK(virt_viewer_session_vnc_auth_unsupported), session); + g_signal_connect(session->priv->vnc, "vnc-server-cut-text", + G_CALLBACK(virt_viewer_session_vnc_cut_text), session); - g_signal_connect(session->priv->vnc, "vnc-auth-credential", - G_CALLBACK(virt_viewer_auth_vnc_credentials), NULL); + g_signal_connect(session->priv->vnc, "vnc-auth-credential", + G_CALLBACK(virt_viewer_auth_vnc_credentials), NULL); - return VIRT_VIEWER_SESSION(session); + return VIRT_VIEWER_SESSION(session); } - - - /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/virt-viewer-session-vnc.h b/src/virt-viewer-session-vnc.h index 2684e45..81b0a80 100644 --- a/src/virt-viewer-session-vnc.h +++ b/src/virt-viewer-session-vnc.h @@ -33,33 +33,33 @@ G_BEGIN_DECLS #define VIRT_VIEWER_TYPE_SESSION_VNC virt_viewer_session_vnc_get_type() -#define VIRT_VIEWER_SESSION_VNC(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIRT_VIEWER_TYPE_SESSION_VNC, VirtViewerSessionVnc)) +#define VIRT_VIEWER_SESSION_VNC(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIRT_VIEWER_TYPE_SESSION_VNC, VirtViewerSessionVnc)) -#define VIRT_VIEWER_SESSION_VNC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), VIRT_VIEWER_TYPE_SESSION_VNC, VirtViewerSessionVncClass)) +#define VIRT_VIEWER_SESSION_VNC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), VIRT_VIEWER_TYPE_SESSION_VNC, VirtViewerSessionVncClass)) -#define VIRT_VIEWER_IS_SESSION_VNC(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIRT_VIEWER_TYPE_SESSION_VNC)) +#define VIRT_VIEWER_IS_SESSION_VNC(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIRT_VIEWER_TYPE_SESSION_VNC)) -#define VIRT_VIEWER_IS_SESSION_VNC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), VIRT_VIEWER_TYPE_SESSION_VNC)) +#define VIRT_VIEWER_IS_SESSION_VNC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), VIRT_VIEWER_TYPE_SESSION_VNC)) -#define VIRT_VIEWER_SESSION_VNC_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), VIRT_VIEWER_TYPE_SESSION_VNC, VirtViewerSessionVncClass)) +#define VIRT_VIEWER_SESSION_VNC_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), VIRT_VIEWER_TYPE_SESSION_VNC, VirtViewerSessionVncClass)) typedef struct _VirtViewerSessionVnc VirtViewerSessionVnc; typedef struct _VirtViewerSessionVncClass VirtViewerSessionVncClass; typedef struct _VirtViewerSessionVncPrivate VirtViewerSessionVncPrivate; struct _VirtViewerSessionVnc { - VirtViewerSession parent; + VirtViewerSession parent; - VirtViewerSessionVncPrivate *priv; + VirtViewerSessionVncPrivate *priv; }; struct _VirtViewerSessionVncClass { - VirtViewerSessionClass parent_class; + VirtViewerSessionClass parent_class; }; GType virt_viewer_session_vnc_get_type(void); @@ -69,11 +69,10 @@ VirtViewerSession *virt_viewer_session_vnc_new(void); G_END_DECLS #endif /* _VIRT_VIEWER_SESSION_VNC_H */ - /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/virt-viewer-session.c b/src/virt-viewer-session.c index 7ed6333..ae3dcb1 100644 --- a/src/virt-viewer-session.c +++ b/src/virt-viewer-session.c @@ -34,355 +34,354 @@ struct _VirtViewerSessionPrivate { - GList *displays; + GList *displays; - gboolean auto_usbredir; + gboolean auto_usbredir; }; G_DEFINE_ABSTRACT_TYPE(VirtViewerSession, virt_viewer_session, G_TYPE_OBJECT) enum { - PROP_0, + PROP_0, - PROP_AUTO_USBREDIR, + PROP_AUTO_USBREDIR, }; static void virt_viewer_session_finalize(GObject *obj) { - VirtViewerSession *session = VIRT_VIEWER_SESSION(obj); - GList *tmp = session->priv->displays; + VirtViewerSession *session = VIRT_VIEWER_SESSION(obj); + GList *tmp = session->priv->displays; - while (tmp) { - g_object_unref(tmp->data); - tmp = tmp->next; - } - g_list_free(session->priv->displays); + while (tmp) { + g_object_unref(tmp->data); + tmp = tmp->next; + } + g_list_free(session->priv->displays); - G_OBJECT_CLASS(virt_viewer_session_parent_class)->finalize(obj); + G_OBJECT_CLASS(virt_viewer_session_parent_class)->finalize(obj); } static void virt_viewer_session_set_property(GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - VirtViewerSession *self = VIRT_VIEWER_SESSION(object); - - switch (prop_id) { - case PROP_AUTO_USBREDIR: - virt_viewer_session_set_auto_usbredir(self, g_value_get_boolean(value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } + VirtViewerSession *self = VIRT_VIEWER_SESSION(object); + + switch (prop_id) { + case PROP_AUTO_USBREDIR: + virt_viewer_session_set_auto_usbredir(self, g_value_get_boolean(value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } } static void virt_viewer_session_get_property(GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { - VirtViewerSession *self = VIRT_VIEWER_SESSION(object); - - switch (prop_id) { - case PROP_AUTO_USBREDIR: - g_value_set_boolean(value, virt_viewer_session_get_auto_usbredir(self)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } + VirtViewerSession *self = VIRT_VIEWER_SESSION(object); + + switch (prop_id) { + case PROP_AUTO_USBREDIR: + g_value_set_boolean(value, virt_viewer_session_get_auto_usbredir(self)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } } static void virt_viewer_session_class_init(VirtViewerSessionClass *class) { - GObjectClass *object_class = G_OBJECT_CLASS(class); - - object_class->set_property = virt_viewer_session_set_property; - object_class->get_property = virt_viewer_session_get_property; - object_class->finalize = virt_viewer_session_finalize; - - g_object_class_install_property(object_class, - PROP_AUTO_USBREDIR, - g_param_spec_boolean("auto-usbredir", - "USB redirection", - "USB redirection", - TRUE, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT | - G_PARAM_STATIC_STRINGS)); - - g_signal_new("session-connected", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET(VirtViewerSessionClass, session_connected), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - g_signal_new("session-initialized", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET(VirtViewerSessionClass, session_initialized), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - g_signal_new("session-disconnected", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET(VirtViewerSessionClass, session_disconnected), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - g_signal_new("session-channel-open", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET(VirtViewerSessionClass, session_channel_open), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, - 1, - G_TYPE_OBJECT); - - g_signal_new("session-auth-refused", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, - G_STRUCT_OFFSET(VirtViewerSessionClass, session_auth_refused), - NULL, - NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, - 1, - G_TYPE_STRING); - - g_signal_new("session-auth-failed", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, - G_STRUCT_OFFSET(VirtViewerSessionClass, session_auth_failed), - NULL, - NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, - 1, - G_TYPE_STRING); - - g_signal_new("session-usb-failed", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, - G_STRUCT_OFFSET(VirtViewerSessionClass, session_usb_failed), - NULL, - NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, - 1, - G_TYPE_STRING); - - g_signal_new("session-display-added", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, - G_STRUCT_OFFSET(VirtViewerSessionClass, session_display_added), - NULL, - NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, - 1, - VIRT_VIEWER_TYPE_DISPLAY); - - g_signal_new("session-display-removed", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, - G_STRUCT_OFFSET(VirtViewerSessionClass, session_display_removed), - NULL, - NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, - 1, - VIRT_VIEWER_TYPE_DISPLAY); - - g_signal_new("session-cut-text", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, - G_STRUCT_OFFSET(VirtViewerSessionClass, session_cut_text), - NULL, - NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, - 1, - G_TYPE_STRING); - - g_signal_new("session-bell", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, - G_STRUCT_OFFSET(VirtViewerSessionClass, session_bell), - NULL, - NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - g_signal_new("session-cancelled", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET(VirtViewerSessionClass, session_cancelled), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - g_type_class_add_private(class, sizeof(VirtViewerSessionPrivate)); + GObjectClass *object_class = G_OBJECT_CLASS(class); + + object_class->set_property = virt_viewer_session_set_property; + object_class->get_property = virt_viewer_session_get_property; + object_class->finalize = virt_viewer_session_finalize; + + g_object_class_install_property(object_class, + PROP_AUTO_USBREDIR, + g_param_spec_boolean("auto-usbredir", + "USB redirection", + "USB redirection", + TRUE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + G_PARAM_STATIC_STRINGS)); + + g_signal_new("session-connected", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET(VirtViewerSessionClass, session_connected), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + + g_signal_new("session-initialized", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET(VirtViewerSessionClass, session_initialized), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + + g_signal_new("session-disconnected", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET(VirtViewerSessionClass, session_disconnected), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + + g_signal_new("session-channel-open", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET(VirtViewerSessionClass, session_channel_open), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, + 1, + G_TYPE_OBJECT); + + g_signal_new("session-auth-refused", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, + G_STRUCT_OFFSET(VirtViewerSessionClass, session_auth_refused), + NULL, + NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, + 1, + G_TYPE_STRING); + + g_signal_new("session-auth-failed", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, + G_STRUCT_OFFSET(VirtViewerSessionClass, session_auth_failed), + NULL, + NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, + 1, + G_TYPE_STRING); + + g_signal_new("session-usb-failed", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, + G_STRUCT_OFFSET(VirtViewerSessionClass, session_usb_failed), + NULL, + NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, + 1, + G_TYPE_STRING); + + g_signal_new("session-display-added", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, + G_STRUCT_OFFSET(VirtViewerSessionClass, session_display_added), + NULL, + NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, + 1, + VIRT_VIEWER_TYPE_DISPLAY); + + g_signal_new("session-display-removed", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, + G_STRUCT_OFFSET(VirtViewerSessionClass, session_display_removed), + NULL, + NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, + 1, + VIRT_VIEWER_TYPE_DISPLAY); + + g_signal_new("session-cut-text", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, + G_STRUCT_OFFSET(VirtViewerSessionClass, session_cut_text), + NULL, + NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, + 1, + G_TYPE_STRING); + + g_signal_new("session-bell", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, + G_STRUCT_OFFSET(VirtViewerSessionClass, session_bell), + NULL, + NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + + g_signal_new("session-cancelled", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET(VirtViewerSessionClass, session_cancelled), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + + g_type_class_add_private(class, sizeof(VirtViewerSessionPrivate)); } static void virt_viewer_session_init(VirtViewerSession *session) { - session->priv = VIRT_VIEWER_SESSION_GET_PRIVATE(session); + session->priv = VIRT_VIEWER_SESSION_GET_PRIVATE(session); } GtkWidget* virt_viewer_session_new(void) { - return g_object_new(VIRT_VIEWER_TYPE_SESSION, NULL); + return g_object_new(VIRT_VIEWER_TYPE_SESSION, NULL); } void virt_viewer_session_add_display(VirtViewerSession *session, - VirtViewerDisplay *display) + VirtViewerDisplay *display) { - session->priv->displays = g_list_append(session->priv->displays, display); - g_object_ref(display); - g_signal_emit_by_name(session, "session-display-added", display); + session->priv->displays = g_list_append(session->priv->displays, display); + g_object_ref(display); + g_signal_emit_by_name(session, "session-display-added", display); } void virt_viewer_session_remove_display(VirtViewerSession *session, - VirtViewerDisplay *display) + VirtViewerDisplay *display) { - if (!g_list_find(session->priv->displays, display)) - return; + if (!g_list_find(session->priv->displays, display)) + return; - session->priv->displays = g_list_remove(session->priv->displays, display); - g_signal_emit_by_name(session, "session-display-removed", display); - g_object_unref(display); + session->priv->displays = g_list_remove(session->priv->displays, display); + g_signal_emit_by_name(session, "session-display-removed", display); + g_object_unref(display); } void virt_viewer_session_clear_displays(VirtViewerSession *session) { - GList *tmp = session->priv->displays; - - while (tmp) { - g_signal_emit_by_name(session, "session-display-removed", tmp->data); - g_object_unref(tmp->data); - tmp = tmp->next; - } - g_list_free(session->priv->displays); - session->priv->displays = NULL; + GList *tmp = session->priv->displays; + + while (tmp) { + g_signal_emit_by_name(session, "session-display-removed", tmp->data); + g_object_unref(tmp->data); + tmp = tmp->next; + } + g_list_free(session->priv->displays); + session->priv->displays = NULL; } void virt_viewer_session_close(VirtViewerSession *session) { - g_return_if_fail(VIRT_VIEWER_IS_SESSION(session)); + g_return_if_fail(VIRT_VIEWER_IS_SESSION(session)); - VIRT_VIEWER_SESSION_GET_CLASS(session)->close(session); + VIRT_VIEWER_SESSION_GET_CLASS(session)->close(session); } gboolean virt_viewer_session_open_fd(VirtViewerSession *session, int fd) { - g_return_val_if_fail(VIRT_VIEWER_IS_SESSION(session), FALSE); + g_return_val_if_fail(VIRT_VIEWER_IS_SESSION(session), FALSE); - return VIRT_VIEWER_SESSION_GET_CLASS(session)->open_fd(session, fd); + return VIRT_VIEWER_SESSION_GET_CLASS(session)->open_fd(session, fd); } gboolean virt_viewer_session_open_host(VirtViewerSession *session, char *host, char *port) { - VirtViewerSessionClass *klass; + VirtViewerSessionClass *klass; - g_return_val_if_fail(VIRT_VIEWER_IS_SESSION(session), FALSE); + g_return_val_if_fail(VIRT_VIEWER_IS_SESSION(session), FALSE); - klass = VIRT_VIEWER_SESSION_GET_CLASS(session); - return klass->open_host(session, host, port); + klass = VIRT_VIEWER_SESSION_GET_CLASS(session); + return klass->open_host(session, host, port); } gboolean virt_viewer_session_open_uri(VirtViewerSession *session, gchar *uri) { - VirtViewerSessionClass *klass; + VirtViewerSessionClass *klass; - g_return_val_if_fail(VIRT_VIEWER_IS_SESSION(session), FALSE); + g_return_val_if_fail(VIRT_VIEWER_IS_SESSION(session), FALSE); - klass = VIRT_VIEWER_SESSION_GET_CLASS(session); - g_return_val_if_fail(klass->open_uri != NULL, FALSE); + klass = VIRT_VIEWER_SESSION_GET_CLASS(session); + g_return_val_if_fail(klass->open_uri != NULL, FALSE); - return klass->open_uri(session, uri); + return klass->open_uri(session, uri); } gboolean virt_viewer_session_channel_open_fd(VirtViewerSession *session, - VirtViewerSessionChannel *channel, int fd) + VirtViewerSessionChannel *channel, int fd) { - g_return_val_if_fail(VIRT_VIEWER_IS_SESSION(session), FALSE); + g_return_val_if_fail(VIRT_VIEWER_IS_SESSION(session), FALSE); - return VIRT_VIEWER_SESSION_GET_CLASS(session)->channel_open_fd(session, channel, fd); + return VIRT_VIEWER_SESSION_GET_CLASS(session)->channel_open_fd(session, channel, fd); } void virt_viewer_session_set_auto_usbredir(VirtViewerSession *self, gboolean auto_usbredir) { - g_return_if_fail(VIRT_VIEWER_IS_SESSION(self)); + g_return_if_fail(VIRT_VIEWER_IS_SESSION(self)); - if (self->priv->auto_usbredir == auto_usbredir) - return; + if (self->priv->auto_usbredir == auto_usbredir) + return; - self->priv->auto_usbredir = auto_usbredir; - g_object_notify(G_OBJECT(self), "auto-usbredir"); + self->priv->auto_usbredir = auto_usbredir; + g_object_notify(G_OBJECT(self), "auto-usbredir"); } gboolean virt_viewer_session_get_auto_usbredir(VirtViewerSession *self) { - g_return_val_if_fail(VIRT_VIEWER_IS_SESSION(self), FALSE); + g_return_val_if_fail(VIRT_VIEWER_IS_SESSION(self), FALSE); - return self->priv->auto_usbredir; + return self->priv->auto_usbredir; } gboolean virt_viewer_session_has_usb(VirtViewerSession *self) { - VirtViewerSessionClass *klass; + VirtViewerSessionClass *klass; - g_return_val_if_fail(VIRT_VIEWER_IS_SESSION(self), FALSE); + g_return_val_if_fail(VIRT_VIEWER_IS_SESSION(self), FALSE); - klass = VIRT_VIEWER_SESSION_GET_CLASS(self); - if (klass->has_usb == NULL) - return FALSE; + klass = VIRT_VIEWER_SESSION_GET_CLASS(self); + if (klass->has_usb == NULL) + return FALSE; - return klass->has_usb(self); + return klass->has_usb(self); } void virt_viewer_session_usb_device_selection(VirtViewerSession *self, - GtkWindow *parent) + GtkWindow *parent) { - VirtViewerSessionClass *klass; + VirtViewerSessionClass *klass; - g_return_if_fail(VIRT_VIEWER_IS_SESSION(self)); + g_return_if_fail(VIRT_VIEWER_IS_SESSION(self)); - klass = VIRT_VIEWER_SESSION_GET_CLASS(self); - g_return_if_fail(klass->usb_device_selection != NULL); + klass = VIRT_VIEWER_SESSION_GET_CLASS(self); + g_return_if_fail(klass->usb_device_selection != NULL); - klass->usb_device_selection(self, parent); + klass->usb_device_selection(self, parent); } /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * indent-tabs-mode: t - * tab-width: 8 + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/virt-viewer-session.h b/src/virt-viewer-session.h index f02c1ee..c33603e 100644 --- a/src/virt-viewer-session.h +++ b/src/virt-viewer-session.h @@ -32,20 +32,20 @@ G_BEGIN_DECLS #define VIRT_VIEWER_TYPE_SESSION virt_viewer_session_get_type() -#define VIRT_VIEWER_SESSION(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIRT_VIEWER_TYPE_SESSION, VirtViewerSession)) +#define VIRT_VIEWER_SESSION(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIRT_VIEWER_TYPE_SESSION, VirtViewerSession)) -#define VIRT_VIEWER_SESSION_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), VIRT_VIEWER_TYPE_SESSION, VirtViewerSessionClass)) +#define VIRT_VIEWER_SESSION_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), VIRT_VIEWER_TYPE_SESSION, VirtViewerSessionClass)) #define VIRT_VIEWER_IS_SESSION(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIRT_VIEWER_TYPE_SESSION)) + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIRT_VIEWER_TYPE_SESSION)) #define VIRT_VIEWER_IS_SESSION_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), VIRT_VIEWER_TYPE_SESSION)) + (G_TYPE_CHECK_CLASS_TYPE ((klass), VIRT_VIEWER_TYPE_SESSION)) -#define VIRT_VIEWER_SESSION_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), VIRT_VIEWER_TYPE_SESSION, VirtViewerSessionClass)) +#define VIRT_VIEWER_SESSION_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), VIRT_VIEWER_TYPE_SESSION, VirtViewerSessionClass)) typedef struct _VirtViewerSession VirtViewerSession; typedef struct _VirtViewerSessionClass VirtViewerSessionClass; @@ -56,41 +56,41 @@ typedef struct _VirtViewerSessionChannel VirtViewerSessionChannel; /* perhaps this become an interface, and be pushed in gtkvnc and spice? */ struct _VirtViewerSession { - GObject parent; + GObject parent; - VirtViewerSessionPrivate *priv; + VirtViewerSessionPrivate *priv; }; struct _VirtViewerSessionClass { - GObjectClass parent_class; - - /* virtual methods */ - void (* close) (VirtViewerSession* session); - gboolean (* open_fd) (VirtViewerSession* session, int fd); - gboolean (* open_host) (VirtViewerSession* session, char *host, char *port); - gboolean (* open_uri) (VirtViewerSession* session, char *uri); - gboolean (* channel_open_fd) (VirtViewerSession* session, VirtViewerSessionChannel *channel, int fd); - gboolean (* has_usb) (VirtViewerSession* session); - void (* usb_device_selection) (VirtViewerSession* session, GtkWindow *parent); - - /* signals */ - void (*session_connected)(VirtViewerSession *session); - void (*session_initialized)(VirtViewerSession *session); - void (*session_disconnected)(VirtViewerSession *session); - void (*session_auth_refused)(VirtViewerSession *session, const char *msg); - void (*session_auth_failed)(VirtViewerSession *session, const char *msg); - void (*session_usb_failed)(VirtViewerSession *session, const char *msg); - - void (*session_channel_open)(VirtViewerSession *session, VirtViewerSessionChannel *channel); - - void (*session_display_added)(VirtViewerSession *session, - VirtViewerDisplay *display); - void (*session_display_removed)(VirtViewerSession *session, - VirtViewerDisplay *display); - - void (*session_cut_text)(VirtViewerSession *session, const char *str); - void (*session_bell)(VirtViewerSession *session); - void (*session_cancelled)(VirtViewerSession *session); + GObjectClass parent_class; + + /* virtual methods */ + void (* close) (VirtViewerSession* session); + gboolean (* open_fd) (VirtViewerSession* session, int fd); + gboolean (* open_host) (VirtViewerSession* session, char *host, char *port); + gboolean (* open_uri) (VirtViewerSession* session, char *uri); + gboolean (* channel_open_fd) (VirtViewerSession* session, VirtViewerSessionChannel *channel, int fd); + gboolean (* has_usb) (VirtViewerSession* session); + void (* usb_device_selection) (VirtViewerSession* session, GtkWindow *parent); + + /* signals */ + void (*session_connected)(VirtViewerSession *session); + void (*session_initialized)(VirtViewerSession *session); + void (*session_disconnected)(VirtViewerSession *session); + void (*session_auth_refused)(VirtViewerSession *session, const char *msg); + void (*session_auth_failed)(VirtViewerSession *session, const char *msg); + void (*session_usb_failed)(VirtViewerSession *session, const char *msg); + + void (*session_channel_open)(VirtViewerSession *session, VirtViewerSessionChannel *channel); + + void (*session_display_added)(VirtViewerSession *session, + VirtViewerDisplay *display); + void (*session_display_removed)(VirtViewerSession *session, + VirtViewerDisplay *display); + + void (*session_cut_text)(VirtViewerSession *session, const char *str); + void (*session_bell)(VirtViewerSession *session); + void (*session_cancelled)(VirtViewerSession *session); }; GType virt_viewer_session_get_type(void); @@ -98,9 +98,9 @@ GType virt_viewer_session_get_type(void); GtkWidget *virt_viewer_session_new(void); void virt_viewer_session_add_display(VirtViewerSession *session, - VirtViewerDisplay *display); + VirtViewerDisplay *display); void virt_viewer_session_remove_display(VirtViewerSession *session, - VirtViewerDisplay *display); + VirtViewerDisplay *display); void virt_viewer_session_clear_displays(VirtViewerSession *session); void virt_viewer_session_close(VirtViewerSession* session); @@ -108,7 +108,7 @@ gboolean virt_viewer_session_open_fd(VirtViewerSession* session, int fd); gboolean virt_viewer_session_open_host(VirtViewerSession* session, char *host, char *port); GObject* virt_viewer_session_get(VirtViewerSession* session); gboolean virt_viewer_session_channel_open_fd(VirtViewerSession* session, - VirtViewerSessionChannel* channel, int fd); + VirtViewerSessionChannel* channel, int fd); gboolean virt_viewer_session_open_uri(VirtViewerSession *session, gchar *uri); void virt_viewer_session_set_auto_usbredir(VirtViewerSession* session, gboolean auto_usbredir); @@ -116,15 +116,16 @@ gboolean virt_viewer_session_get_auto_usbredir(VirtViewerSession* session); gboolean virt_viewer_session_has_usb(VirtViewerSession *self); void virt_viewer_session_usb_device_selection(VirtViewerSession *self, - GtkWindow *parent); + GtkWindow *parent); G_END_DECLS #endif /* _VIRT_VIEWER_SESSION_H */ + /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/virt-viewer-util.c b/src/virt-viewer-util.c index 5037564..fa37b62 100644 --- a/src/virt-viewer-util.c +++ b/src/virt-viewer-util.c @@ -34,42 +34,42 @@ GtkBuilder *virt_viewer_util_load_ui(const char *name) { - struct stat sb; - GtkBuilder *builder; - GError *error = NULL; - - builder = gtk_builder_new(); - if (stat(name, &sb) >= 0) { - gtk_builder_add_from_file(builder, name, &error); - } else { - const gchar * const * dirs = g_get_system_data_dirs(); - g_return_val_if_fail(dirs != NULL, NULL); - - while (dirs[0] != NULL) { - gchar *path = g_build_filename(dirs[0], PACKAGE, "ui", name, NULL); - if (gtk_builder_add_from_file(builder, path, NULL) != 0) { - g_free(path); - break; - } - g_free(path); - dirs++; - } - if (dirs[0] == NULL) - goto failed; - } - - if (error) { - g_error("Cannot load UI description %s: %s", name, - error->message); - g_clear_error(&error); - goto failed; + struct stat sb; + GtkBuilder *builder; + GError *error = NULL; + + builder = gtk_builder_new(); + if (stat(name, &sb) >= 0) { + gtk_builder_add_from_file(builder, name, &error); + } else { + const gchar * const * dirs = g_get_system_data_dirs(); + g_return_val_if_fail(dirs != NULL, NULL); + + while (dirs[0] != NULL) { + gchar *path = g_build_filename(dirs[0], PACKAGE, "ui", name, NULL); + if (gtk_builder_add_from_file(builder, path, NULL) != 0) { + g_free(path); + break; + } + g_free(path); + dirs++; } - - return builder; -failed: - g_error("failed to find UI description file"); - g_object_unref(builder); - return NULL; + if (dirs[0] == NULL) + goto failed; + } + + if (error) { + g_error("Cannot load UI description %s: %s", name, + error->message); + g_clear_error(&error); + goto failed; + } + + return builder; + failed: + g_error("failed to find UI description file"); + g_object_unref(builder); + return NULL; } int @@ -80,57 +80,57 @@ virt_viewer_util_extract_host(const char *uristr, char **user, int *port) { - xmlURIPtr uri; - char *offset; - - if (uristr == NULL || - !g_ascii_strcasecmp(uristr, "xen")) - uristr = "xen:///"; - - uri = xmlParseURI(uristr); - g_return_val_if_fail(uri != NULL, 1); - - if (host) { - if (!uri || !uri->server) - *host = g_strdup("localhost"); - else - *host = g_strdup(uri->server); - } - - if (user) { - if (uri->user) - *user = g_strdup(uri->user); - else - *user = NULL; - } - - if (port) - *port = uri->port; - - offset = strchr(uri->scheme, '+'); - - if (transport) { - if (offset) - *transport = g_strdup(offset+1); - else - *transport = NULL; - } - - if (scheme) { - if (offset) - *scheme = g_strndup(uri->scheme, offset - uri->scheme); - else - *scheme = g_strdup(uri->scheme); - } - - xmlFreeURI(uri); - return 0; + xmlURIPtr uri; + char *offset; + + if (uristr == NULL || + !g_ascii_strcasecmp(uristr, "xen")) + uristr = "xen:///"; + + uri = xmlParseURI(uristr); + g_return_val_if_fail(uri != NULL, 1); + + if (host) { + if (!uri || !uri->server) + *host = g_strdup("localhost"); + else + *host = g_strdup(uri->server); + } + + if (user) { + if (uri->user) + *user = g_strdup(uri->user); + else + *user = NULL; + } + + if (port) + *port = uri->port; + + offset = strchr(uri->scheme, '+'); + + if (transport) { + if (offset) + *transport = g_strdup(offset+1); + else + *transport = NULL; + } + + if (scheme) { + if (offset) + *scheme = g_strndup(uri->scheme, offset - uri->scheme); + else + *scheme = g_strdup(uri->scheme); + } + + xmlFreeURI(uri); + return 0; } /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/virt-viewer-util.h b/src/virt-viewer-util.h index 034ab8f..e0249f4 100644 --- a/src/virt-viewer-util.h +++ b/src/virt-viewer-util.h @@ -41,3 +41,11 @@ int virt_viewer_util_extract_host(const char *uristr, int *port); #endif + +/* + * Local variables: + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c index 1a13e16..437deb1 100644 --- a/src/virt-viewer-window.c +++ b/src/virt-viewer-window.c @@ -61,49 +61,49 @@ static void virt_viewer_window_toolbar_setup(VirtViewerWindow *self); G_DEFINE_TYPE (VirtViewerWindow, virt_viewer_window, G_TYPE_OBJECT) -#define GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), VIRT_VIEWER_TYPE_WINDOW, VirtViewerWindowPrivate)) +#define GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), VIRT_VIEWER_TYPE_WINDOW, VirtViewerWindowPrivate)) enum { - PROP_0, - PROP_WINDOW, - PROP_DISPLAY, - PROP_SUBTITLE, - PROP_CONTAINER, - PROP_APP, + PROP_0, + PROP_WINDOW, + PROP_DISPLAY, + PROP_SUBTITLE, + PROP_CONTAINER, + PROP_APP, }; enum menuNums { - FILE_MENU, - VIEW_MENU, - SEND_KEY_MENU, - HELP_MENU, - LAST_MENU // sentinel + FILE_MENU, + VIEW_MENU, + SEND_KEY_MENU, + HELP_MENU, + LAST_MENU // sentinel }; struct _VirtViewerWindowPrivate { - VirtViewerApp *app; - GtkContainer *container; /* if any, then there is no window */ - - GtkBuilder *builder; - GtkWidget *window; - GtkWidget *layout; - GtkWidget *toolbar; - VirtViewerNotebook *notebook; - VirtViewerDisplay *display; - - gboolean accel_enabled; - GValue accel_setting; - GSList *accel_list; - int accel_menu_sig[LAST_MENU]; - gboolean grabbed; - gboolean before_saved; - GdkRectangle before_fullscreen; - - gint zoomlevel; - gboolean auto_resize; - gboolean fullscreen; - gchar *subtitle; + VirtViewerApp *app; + GtkContainer *container; /* if any, then there is no window */ + + GtkBuilder *builder; + GtkWidget *window; + GtkWidget *layout; + GtkWidget *toolbar; + VirtViewerNotebook *notebook; + VirtViewerDisplay *display; + + gboolean accel_enabled; + GValue accel_setting; + GSList *accel_list; + int accel_menu_sig[LAST_MENU]; + gboolean grabbed; + gboolean before_saved; + GdkRectangle before_fullscreen; + + gint zoomlevel; + gboolean auto_resize; + gboolean fullscreen; + gchar *subtitle; }; #if GTK_CHECK_VERSION(3, 0, 0) @@ -128,248 +128,248 @@ struct _VirtViewerWindowPrivate { static void virt_viewer_window_get_property (GObject *object, guint property_id, - GValue *value, GParamSpec *pspec) + GValue *value, GParamSpec *pspec) { - VirtViewerWindowPrivate *priv = VIRT_VIEWER_WINDOW(object)->priv; + VirtViewerWindowPrivate *priv = VIRT_VIEWER_WINDOW(object)->priv; - switch (property_id) { - case PROP_SUBTITLE: - g_value_set_string(value, priv->subtitle); - break; + switch (property_id) { + case PROP_SUBTITLE: + g_value_set_string(value, priv->subtitle); + break; - case PROP_WINDOW: - g_value_set_object(value, priv->window); - break; + case PROP_WINDOW: + g_value_set_object(value, priv->window); + break; - case PROP_DISPLAY: - g_value_set_object(value, priv->display); - break; + case PROP_DISPLAY: + g_value_set_object(value, priv->display); + break; - case PROP_CONTAINER: - g_value_set_object(value, priv->container); - break; + case PROP_CONTAINER: + g_value_set_object(value, priv->container); + break; - case PROP_APP: - g_value_set_object(value, priv->app); - break; + case PROP_APP: + g_value_set_object(value, priv->app); + break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } } static void virt_viewer_window_set_property (GObject *object, guint property_id, - const GValue *value, GParamSpec *pspec) + const GValue *value, GParamSpec *pspec) { - VirtViewerWindowPrivate *priv = VIRT_VIEWER_WINDOW(object)->priv; + VirtViewerWindowPrivate *priv = VIRT_VIEWER_WINDOW(object)->priv; - switch (property_id) { - case PROP_SUBTITLE: - g_free(priv->subtitle); - priv->subtitle = g_value_dup_string(value); - virt_viewer_window_update_title(VIRT_VIEWER_WINDOW(object)); - break; + switch (property_id) { + case PROP_SUBTITLE: + g_free(priv->subtitle); + priv->subtitle = g_value_dup_string(value); + virt_viewer_window_update_title(VIRT_VIEWER_WINDOW(object)); + break; - case PROP_CONTAINER: - g_return_if_fail(priv->container == NULL); - priv->container = g_value_dup_object(value); - break; + case PROP_CONTAINER: + g_return_if_fail(priv->container == NULL); + priv->container = g_value_dup_object(value); + break; - case PROP_APP: - g_return_if_fail(priv->app == NULL); - priv->app = g_value_dup_object(value); - break; + case PROP_APP: + g_return_if_fail(priv->app == NULL); + priv->app = g_value_dup_object(value); + break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } } static void virt_viewer_window_dispose (GObject *object) { - VirtViewerWindowPrivate *priv = VIRT_VIEWER_WINDOW(object)->priv; - G_OBJECT_CLASS (virt_viewer_window_parent_class)->dispose (object); + VirtViewerWindowPrivate *priv = VIRT_VIEWER_WINDOW(object)->priv; + G_OBJECT_CLASS (virt_viewer_window_parent_class)->dispose (object); - if (priv->display) { - g_object_unref(priv->display); - priv->display = NULL; - } + if (priv->display) { + g_object_unref(priv->display); + priv->display = NULL; + } - if (priv->app) { - g_object_unref(priv->app); - priv->app = NULL; - } + if (priv->app) { + g_object_unref(priv->app); + priv->app = NULL; + } - g_free(priv->subtitle); - priv->subtitle = NULL; + g_free(priv->subtitle); + priv->subtitle = NULL; } static void virt_viewer_window_class_init (VirtViewerWindowClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (VirtViewerWindowPrivate)); - - object_class->get_property = virt_viewer_window_get_property; - object_class->set_property = virt_viewer_window_set_property; - object_class->dispose = virt_viewer_window_dispose; - - g_object_class_install_property(object_class, - PROP_SUBTITLE, - g_param_spec_string("subtitle", - "Subtitle", - "Window subtitle", - "", - G_PARAM_READABLE | - G_PARAM_WRITABLE | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property(object_class, - PROP_WINDOW, - g_param_spec_object("window", - "Window", - "GtkWindow", - GTK_TYPE_WIDGET, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property(object_class, - PROP_DISPLAY, - g_param_spec_object("display", - "Display", - "VirtDisplay", - VIRT_VIEWER_TYPE_DISPLAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property(object_class, - PROP_CONTAINER, - g_param_spec_object("container", - "Container", - "Container widget", - VIRT_VIEWER_TYPE_DISPLAY, - G_PARAM_READABLE | - G_PARAM_WRITABLE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property(object_class, - PROP_APP, - g_param_spec_object("app", - "App", - "VirtViewerApp", - VIRT_VIEWER_TYPE_APP, - G_PARAM_READABLE | - G_PARAM_WRITABLE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (VirtViewerWindowPrivate)); + + object_class->get_property = virt_viewer_window_get_property; + object_class->set_property = virt_viewer_window_set_property; + object_class->dispose = virt_viewer_window_dispose; + + g_object_class_install_property(object_class, + PROP_SUBTITLE, + g_param_spec_string("subtitle", + "Subtitle", + "Window subtitle", + "", + G_PARAM_READABLE | + G_PARAM_WRITABLE | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property(object_class, + PROP_WINDOW, + g_param_spec_object("window", + "Window", + "GtkWindow", + GTK_TYPE_WIDGET, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property(object_class, + PROP_DISPLAY, + g_param_spec_object("display", + "Display", + "VirtDisplay", + VIRT_VIEWER_TYPE_DISPLAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property(object_class, + PROP_CONTAINER, + g_param_spec_object("container", + "Container", + "Container widget", + VIRT_VIEWER_TYPE_DISPLAY, + G_PARAM_READABLE | + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property(object_class, + PROP_APP, + g_param_spec_object("app", + "App", + "VirtViewerApp", + VIRT_VIEWER_TYPE_APP, + G_PARAM_READABLE | + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); } static void virt_viewer_window_init (VirtViewerWindow *self) { - VirtViewerWindowPrivate *priv; - GtkWidget *vbox; - GtkWidget *menu; - GdkColor color; - GSList *accels; + VirtViewerWindowPrivate *priv; + GtkWidget *vbox; + GtkWidget *menu; + GdkColor color; + GSList *accels; - self->priv = GET_PRIVATE(self); - priv = self->priv; + self->priv = GET_PRIVATE(self); + priv = self->priv; - priv->auto_resize = TRUE; - g_value_init(&priv->accel_setting, G_TYPE_STRING); + priv->auto_resize = TRUE; + g_value_init(&priv->accel_setting, G_TYPE_STRING); - priv->notebook = virt_viewer_notebook_new(); - priv->builder = virt_viewer_util_load_ui("virt-viewer.xml"); + priv->notebook = virt_viewer_notebook_new(); + priv->builder = virt_viewer_util_load_ui("virt-viewer.xml"); - menu = GTK_WIDGET(gtk_builder_get_object(priv->builder, "menu-view-resize")); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), TRUE); + menu = GTK_WIDGET(gtk_builder_get_object(priv->builder, "menu-view-resize")); + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), TRUE); - gtk_builder_connect_signals(priv->builder, self); + gtk_builder_connect_signals(priv->builder, self); - vbox = GTK_WIDGET(gtk_builder_get_object(priv->builder, "viewer-box")); - virt_viewer_window_toolbar_setup(self); + vbox = GTK_WIDGET(gtk_builder_get_object(priv->builder, "viewer-box")); + virt_viewer_window_toolbar_setup(self); - gtk_box_pack_end(GTK_BOX(vbox), priv->layout, TRUE, TRUE, 0); - gdk_color_parse("black", &color); - gtk_widget_modify_bg(priv->layout, GTK_STATE_NORMAL, &color); + gtk_box_pack_end(GTK_BOX(vbox), priv->layout, TRUE, TRUE, 0); + gdk_color_parse("black", &color); + gtk_widget_modify_bg(priv->layout, GTK_STATE_NORMAL, &color); - priv->window = GTK_WIDGET(gtk_builder_get_object(priv->builder, "viewer")); + priv->window = GTK_WIDGET(gtk_builder_get_object(priv->builder, "viewer")); - virt_viewer_window_update_title(self); - gtk_window_set_resizable(GTK_WINDOW(priv->window), TRUE); + virt_viewer_window_update_title(self); + gtk_window_set_resizable(GTK_WINDOW(priv->window), TRUE); #if GTK_CHECK_VERSION(3, 0, 0) - gtk_window_set_has_resize_grip(GTK_WINDOW(priv->window), FALSE); + gtk_window_set_has_resize_grip(GTK_WINDOW(priv->window), FALSE); #endif - priv->accel_enabled = TRUE; + priv->accel_enabled = TRUE; - accels = gtk_accel_groups_from_object(G_OBJECT(priv->window)); - for ( ; accels ; accels = accels->next) { - priv->accel_list = g_slist_append(priv->accel_list, accels->data); - g_object_ref(G_OBJECT(accels->data)); - } + accels = gtk_accel_groups_from_object(G_OBJECT(priv->window)); + for ( ; accels ; accels = accels->next) { + priv->accel_list = g_slist_append(priv->accel_list, accels->data); + g_object_ref(G_OBJECT(accels->data)); + } - priv->zoomlevel = 100; + priv->zoomlevel = 100; } static void virt_viewer_window_desktop_resize(VirtViewerDisplay *display G_GNUC_UNUSED, - VirtViewerWindow *self) + VirtViewerWindow *self) { - VirtViewerWindowPrivate *priv = self->priv; - if (priv->auto_resize && priv->window && !priv->fullscreen) - virt_viewer_window_resize(self); + VirtViewerWindowPrivate *priv = self->priv; + if (priv->auto_resize && priv->window && !priv->fullscreen) + virt_viewer_window_resize(self); } G_MODULE_EXPORT void virt_viewer_window_menu_view_zoom_out(GtkWidget *menu G_GNUC_UNUSED, - VirtViewerWindow *self) + VirtViewerWindow *self) { - VirtViewerWindowPrivate *priv = self->priv; + VirtViewerWindowPrivate *priv = self->priv; - if (priv->zoomlevel > 10) - priv->zoomlevel -= 10; + if (priv->zoomlevel > 10) + priv->zoomlevel -= 10; - if (!priv->display) - return; + if (!priv->display) + return; - gtk_window_resize(GTK_WINDOW(priv->window), 1, 1); - if (priv->display) - virt_viewer_display_set_zoom_level(VIRT_VIEWER_DISPLAY(priv->display), priv->zoomlevel); + gtk_window_resize(GTK_WINDOW(priv->window), 1, 1); + if (priv->display) + virt_viewer_display_set_zoom_level(VIRT_VIEWER_DISPLAY(priv->display), priv->zoomlevel); } G_MODULE_EXPORT void virt_viewer_window_menu_view_zoom_in(GtkWidget *menu G_GNUC_UNUSED, - VirtViewerWindow *self) + VirtViewerWindow *self) { - VirtViewerWindowPrivate *priv = self->priv; + VirtViewerWindowPrivate *priv = self->priv; - if (priv->zoomlevel < 400) - priv->zoomlevel += 10; + if (priv->zoomlevel < 400) + priv->zoomlevel += 10; - if (!priv->display) - return; + if (!priv->display) + return; - gtk_window_resize(GTK_WINDOW(priv->window), 1, 1); - if (priv->display) - virt_viewer_display_set_zoom_level(VIRT_VIEWER_DISPLAY(priv->display), priv->zoomlevel); + gtk_window_resize(GTK_WINDOW(priv->window), 1, 1); + if (priv->display) + virt_viewer_display_set_zoom_level(VIRT_VIEWER_DISPLAY(priv->display), priv->zoomlevel); } G_MODULE_EXPORT void virt_viewer_window_menu_view_zoom_reset(GtkWidget *menu G_GNUC_UNUSED, - VirtViewerWindow *self) + VirtViewerWindow *self) { - VirtViewerWindowPrivate *priv = self->priv; - gtk_window_resize(GTK_WINDOW(priv->window), 1, 1); - priv->zoomlevel = 100; + VirtViewerWindowPrivate *priv = self->priv; + gtk_window_resize(GTK_WINDOW(priv->window), 1, 1); + priv->zoomlevel = 100; - if (priv->display) - virt_viewer_display_set_zoom_level(VIRT_VIEWER_DISPLAY(priv->display), priv->zoomlevel); + if (priv->display) + virt_viewer_display_set_zoom_level(VIRT_VIEWER_DISPLAY(priv->display), priv->zoomlevel); } /* @@ -381,576 +381,575 @@ virt_viewer_window_menu_view_zoom_reset(GtkWidget *menu G_GNUC_UNUSED, static void virt_viewer_window_resize(VirtViewerWindow *self) { - GdkRectangle fullscreen; - GdkScreen *screen; - int width, height; - double desktopAspect; - double screenAspect; - guint desktopWidth; - guint desktopHeight; - VirtViewerWindowPrivate *priv = self->priv; - - DEBUG_LOG("Preparing main window resize"); - if (!priv->display) { - DEBUG_LOG("Skipping inactive resize"); - return; - } - - gtk_window_resize(GTK_WINDOW(priv->window), 1, 1); - - virt_viewer_display_get_desktop_size(VIRT_VIEWER_DISPLAY(priv->display), - &desktopWidth, &desktopHeight); - - screen = gtk_widget_get_screen(priv->window); - gdk_screen_get_monitor_geometry(screen, - gdk_screen_get_monitor_at_window - (screen, gtk_widget_get_window(priv->window)), - &fullscreen); - - desktopAspect = (double)desktopWidth / (double)desktopHeight; - screenAspect = (double)(fullscreen.width - 128) / (double)(fullscreen.height - 128); - - if ((desktopWidth > (fullscreen.width - 128)) || - (desktopHeight > (fullscreen.height - 128))) { - /* Doesn't fit native res, so go as large as possible - maintaining aspect ratio */ - if (screenAspect > desktopAspect) { - width = desktopHeight * desktopAspect; - height = desktopHeight; - } else { - width = desktopWidth; - height = desktopWidth / desktopAspect; - } - } else { - width = desktopWidth; - height = desktopHeight; - } - - DEBUG_LOG("Decided todo %dx%d (desktop is %dx%d, fullscreen is %dx%d", - width, height, desktopWidth, desktopHeight, - fullscreen.width, fullscreen.height); - - virt_viewer_display_set_desktop_size(VIRT_VIEWER_DISPLAY(priv->display), - width, height); + GdkRectangle fullscreen; + GdkScreen *screen; + int width, height; + double desktopAspect; + double screenAspect; + guint desktopWidth; + guint desktopHeight; + VirtViewerWindowPrivate *priv = self->priv; + + DEBUG_LOG("Preparing main window resize"); + if (!priv->display) { + DEBUG_LOG("Skipping inactive resize"); + return; + } + + gtk_window_resize(GTK_WINDOW(priv->window), 1, 1); + + virt_viewer_display_get_desktop_size(VIRT_VIEWER_DISPLAY(priv->display), + &desktopWidth, &desktopHeight); + + screen = gtk_widget_get_screen(priv->window); + gdk_screen_get_monitor_geometry(screen, + gdk_screen_get_monitor_at_window + (screen, gtk_widget_get_window(priv->window)), + &fullscreen); + + desktopAspect = (double)desktopWidth / (double)desktopHeight; + screenAspect = (double)(fullscreen.width - 128) / (double)(fullscreen.height - 128); + + if ((desktopWidth > (fullscreen.width - 128)) || + (desktopHeight > (fullscreen.height - 128))) { + /* Doesn't fit native res, so go as large as possible + maintaining aspect ratio */ + if (screenAspect > desktopAspect) { + width = desktopHeight * desktopAspect; + height = desktopHeight; + } else { + width = desktopWidth; + height = desktopWidth / desktopAspect; + } + } else { + width = desktopWidth; + height = desktopHeight; + } + + DEBUG_LOG("Decided todo %dx%d (desktop is %dx%d, fullscreen is %dx%d", + width, height, desktopWidth, desktopHeight, + fullscreen.width, fullscreen.height); + + virt_viewer_display_set_desktop_size(VIRT_VIEWER_DISPLAY(priv->display), + width, height); } void virt_viewer_window_leave_fullscreen(VirtViewerWindow *self) { - VirtViewerWindowPrivate *priv = self->priv; - GtkWidget *menu = GTK_WIDGET(gtk_builder_get_object(priv->builder, "top-menu")); - GtkCheckMenuItem *check = GTK_CHECK_MENU_ITEM(gtk_builder_get_object(priv->builder, "menu-view-fullscreen")); + VirtViewerWindowPrivate *priv = self->priv; + GtkWidget *menu = GTK_WIDGET(gtk_builder_get_object(priv->builder, "top-menu")); + GtkCheckMenuItem *check = GTK_CHECK_MENU_ITEM(gtk_builder_get_object(priv->builder, "menu-view-fullscreen")); - if (!priv->fullscreen) - return; + if (!priv->fullscreen) + return; - gtk_check_menu_item_set_active(check, FALSE); - priv->fullscreen = FALSE; - ViewAutoDrawer_SetActive(VIEW_AUTODRAWER(priv->layout), FALSE); - gtk_widget_show(menu); - gtk_widget_hide(priv->toolbar); + gtk_check_menu_item_set_active(check, FALSE); + priv->fullscreen = FALSE; + ViewAutoDrawer_SetActive(VIEW_AUTODRAWER(priv->layout), FALSE); + gtk_widget_show(menu); + gtk_widget_hide(priv->toolbar); #ifdef G_OS_WIN32 - gtk_widget_set_size_request(GTK_WIDGET(priv->window), -1, -1); + gtk_widget_set_size_request(GTK_WIDGET(priv->window), -1, -1); #endif - gtk_window_unfullscreen(GTK_WINDOW(priv->window)); + gtk_window_unfullscreen(GTK_WINDOW(priv->window)); - if (priv->before_saved) { - gtk_window_move(GTK_WINDOW(priv->window), - priv->before_fullscreen.x, - priv->before_fullscreen.y); - gtk_window_resize(GTK_WINDOW(priv->window), - priv->before_fullscreen.width, - priv->before_fullscreen.height); - priv->before_saved = FALSE; - } + if (priv->before_saved) { + gtk_window_move(GTK_WINDOW(priv->window), + priv->before_fullscreen.x, + priv->before_fullscreen.y); + gtk_window_resize(GTK_WINDOW(priv->window), + priv->before_fullscreen.width, + priv->before_fullscreen.height); + priv->before_saved = FALSE; + } } void virt_viewer_window_enter_fullscreen(VirtViewerWindow *self, gboolean move, gint x, gint y) { - VirtViewerWindowPrivate *priv = self->priv; - GtkWidget *menu = GTK_WIDGET(gtk_builder_get_object(priv->builder, "top-menu")); - GtkCheckMenuItem *check = GTK_CHECK_MENU_ITEM(gtk_builder_get_object(priv->builder, "menu-view-fullscreen")); - - if (!priv->before_saved) { - gtk_window_get_position(GTK_WINDOW(priv->window), - &priv->before_fullscreen.x, - &priv->before_fullscreen.y); - gtk_window_get_size(GTK_WINDOW(priv->window), - &priv->before_fullscreen.width, - &priv->before_fullscreen.height); - priv->before_saved = TRUE; - } - - if (!priv->fullscreen) { - gtk_check_menu_item_set_active(check, TRUE); - priv->fullscreen = TRUE; - gtk_widget_hide(menu); - gtk_widget_show(priv->toolbar); - ViewAutoDrawer_SetActive(VIEW_AUTODRAWER(priv->layout), TRUE); - ViewAutoDrawer_Close(VIEW_AUTODRAWER(priv->layout)); - } - - if (move) - gtk_window_move(GTK_WINDOW(priv->window), x, y); - - gtk_window_fullscreen(GTK_WINDOW(priv->window)); + VirtViewerWindowPrivate *priv = self->priv; + GtkWidget *menu = GTK_WIDGET(gtk_builder_get_object(priv->builder, "top-menu")); + GtkCheckMenuItem *check = GTK_CHECK_MENU_ITEM(gtk_builder_get_object(priv->builder, "menu-view-fullscreen")); + + if (!priv->before_saved) { + gtk_window_get_position(GTK_WINDOW(priv->window), + &priv->before_fullscreen.x, + &priv->before_fullscreen.y); + gtk_window_get_size(GTK_WINDOW(priv->window), + &priv->before_fullscreen.width, + &priv->before_fullscreen.height); + priv->before_saved = TRUE; + } + + if (!priv->fullscreen) { + gtk_check_menu_item_set_active(check, TRUE); + priv->fullscreen = TRUE; + gtk_widget_hide(menu); + gtk_widget_show(priv->toolbar); + ViewAutoDrawer_SetActive(VIEW_AUTODRAWER(priv->layout), TRUE); + ViewAutoDrawer_Close(VIEW_AUTODRAWER(priv->layout)); + } + + if (move) + gtk_window_move(GTK_WINDOW(priv->window), x, y); + + gtk_window_fullscreen(GTK_WINDOW(priv->window)); #ifdef G_OS_WIN32 - /* on windows, fullscreen doesn't always hide the taskbar - See https://bugzilla.gnome.org/show_bug.cgi?id=652049 */ - gtk_widget_set_size_request(GTK_WIDGET(priv->window), - gdk_screen_width(), - gdk_screen_height()); + /* on windows, fullscreen doesn't always hide the taskbar + See https://bugzilla.gnome.org/show_bug.cgi?id=652049 */ + gtk_widget_set_size_request(GTK_WIDGET(priv->window), + gdk_screen_width(), + gdk_screen_height()); #endif } #define MAX_KEY_COMBO 3 -struct keyComboDef { - guint keys[MAX_KEY_COMBO]; - guint nkeys; - const char *label; +struct keyComboDef { + guint keys[MAX_KEY_COMBO]; + guint nkeys; + const char *label; }; static const struct keyComboDef keyCombos[] = { - { { GDK_Control_L, GDK_Alt_L, GDK_Delete }, 3, "Ctrl+Alt+_Del"}, - { { GDK_Control_L, GDK_Alt_L, GDK_BackSpace }, 3, "Ctrl+Alt+_Backspace"}, - { {}, 0, "" }, - { { GDK_Control_L, GDK_Alt_L, GDK_F1 }, 3, "Ctrl+Alt+F_1"}, - { { GDK_Control_L, GDK_Alt_L, GDK_F2 }, 3, "Ctrl+Alt+F_2"}, - { { GDK_Control_L, GDK_Alt_L, GDK_F3 }, 3, "Ctrl+Alt+F_3"}, - { { GDK_Control_L, GDK_Alt_L, GDK_F4 }, 3, "Ctrl+Alt+F_4"}, - { { GDK_Control_L, GDK_Alt_L, GDK_F5 }, 3, "Ctrl+Alt+F_5"}, - { { GDK_Control_L, GDK_Alt_L, GDK_F6 }, 3, "Ctrl+Alt+F_6"}, - { { GDK_Control_L, GDK_Alt_L, GDK_F7 }, 3, "Ctrl+Alt+F_7"}, - { { GDK_Control_L, GDK_Alt_L, GDK_F8 }, 3, "Ctrl+Alt+F_8"}, - { { GDK_Control_L, GDK_Alt_L, GDK_F9 }, 3, "Ctrl+Alt+F_9"}, - { { GDK_Control_L, GDK_Alt_L, GDK_F10 }, 3, "Ctrl+Alt+F1_0"}, - { { GDK_Control_L, GDK_Alt_L, GDK_F11 }, 3, "Ctrl+Alt+F11"}, - { { GDK_Control_L, GDK_Alt_L, GDK_F12 }, 3, "Ctrl+Alt+F12"}, - { {}, 0, "" }, - { { GDK_Print }, 1, "_PrintScreen"}, + { { GDK_Control_L, GDK_Alt_L, GDK_Delete }, 3, "Ctrl+Alt+_Del"}, + { { GDK_Control_L, GDK_Alt_L, GDK_BackSpace }, 3, "Ctrl+Alt+_Backspace"}, + { {}, 0, "" }, + { { GDK_Control_L, GDK_Alt_L, GDK_F1 }, 3, "Ctrl+Alt+F_1"}, + { { GDK_Control_L, GDK_Alt_L, GDK_F2 }, 3, "Ctrl+Alt+F_2"}, + { { GDK_Control_L, GDK_Alt_L, GDK_F3 }, 3, "Ctrl+Alt+F_3"}, + { { GDK_Control_L, GDK_Alt_L, GDK_F4 }, 3, "Ctrl+Alt+F_4"}, + { { GDK_Control_L, GDK_Alt_L, GDK_F5 }, 3, "Ctrl+Alt+F_5"}, + { { GDK_Control_L, GDK_Alt_L, GDK_F6 }, 3, "Ctrl+Alt+F_6"}, + { { GDK_Control_L, GDK_Alt_L, GDK_F7 }, 3, "Ctrl+Alt+F_7"}, + { { GDK_Control_L, GDK_Alt_L, GDK_F8 }, 3, "Ctrl+Alt+F_8"}, + { { GDK_Control_L, GDK_Alt_L, GDK_F9 }, 3, "Ctrl+Alt+F_9"}, + { { GDK_Control_L, GDK_Alt_L, GDK_F10 }, 3, "Ctrl+Alt+F1_0"}, + { { GDK_Control_L, GDK_Alt_L, GDK_F11 }, 3, "Ctrl+Alt+F11"}, + { { GDK_Control_L, GDK_Alt_L, GDK_F12 }, 3, "Ctrl+Alt+F12"}, + { {}, 0, "" }, + { { GDK_Print }, 1, "_PrintScreen"}, }; G_MODULE_EXPORT void virt_viewer_window_menu_send(GtkWidget *menu G_GNUC_UNUSED, - VirtViewerWindow *self) + VirtViewerWindow *self) { - int i; - GtkWidget *label = gtk_bin_get_child(GTK_BIN(menu)); - const char *text = gtk_label_get_label(GTK_LABEL(label)); - VirtViewerWindowPrivate *priv = self->priv; + int i; + GtkWidget *label = gtk_bin_get_child(GTK_BIN(menu)); + const char *text = gtk_label_get_label(GTK_LABEL(label)); + VirtViewerWindowPrivate *priv = self->priv; - for (i = 0 ; i < G_N_ELEMENTS(keyCombos) ; i++) { - if (!strcmp(text, keyCombos[i].label)) { - DEBUG_LOG("Sending key combo %s", gtk_label_get_text(GTK_LABEL(label))); - virt_viewer_display_send_keys(VIRT_VIEWER_DISPLAY(priv->display), - keyCombos[i].keys, - keyCombos[i].nkeys); - return; - } - } - DEBUG_LOG("Failed to find key combo %s", gtk_label_get_text(GTK_LABEL(label))); + for (i = 0 ; i < G_N_ELEMENTS(keyCombos) ; i++) { + if (!strcmp(text, keyCombos[i].label)) { + DEBUG_LOG("Sending key combo %s", gtk_label_get_text(GTK_LABEL(label))); + virt_viewer_display_send_keys(VIRT_VIEWER_DISPLAY(priv->display), + keyCombos[i].keys, + keyCombos[i].nkeys); + return; + } + } + DEBUG_LOG("Failed to find key combo %s", gtk_label_get_text(GTK_LABEL(label))); } static gboolean virt_viewer_window_ignore_accel(GtkWidget *menu G_GNUC_UNUSED, - VirtViewerWindow *self G_GNUC_UNUSED) + VirtViewerWindow *self G_GNUC_UNUSED) { - /* ignore accelerator */ - return TRUE; + /* ignore accelerator */ + return TRUE; } static const char * const menuNames[LAST_MENU] = { - "menu-file", "menu-view", "menu-send", "menu-help" + "menu-file", "menu-view", "menu-send", "menu-help" }; void virt_viewer_window_disable_modifiers(VirtViewerWindow *self) { - GtkSettings *settings = gtk_settings_get_default(); - VirtViewerWindowPrivate *priv = self->priv; - GValue empty; - GSList *accels; - int i; + GtkSettings *settings = gtk_settings_get_default(); + VirtViewerWindowPrivate *priv = self->priv; + GValue empty; + GSList *accels; + int i; - if (!priv->window) - return; + if (!priv->window) + return; - if (!priv->accel_enabled) - return; + if (!priv->accel_enabled) + return; - /* This stops F10 activating menu bar */ - memset(&empty, 0, sizeof empty); - g_value_init(&empty, G_TYPE_STRING); - g_object_get_property(G_OBJECT(settings), "gtk-menu-bar-accel", &priv->accel_setting); - g_object_set_property(G_OBJECT(settings), "gtk-menu-bar-accel", &empty); + /* This stops F10 activating menu bar */ + memset(&empty, 0, sizeof empty); + g_value_init(&empty, G_TYPE_STRING); + g_object_get_property(G_OBJECT(settings), "gtk-menu-bar-accel", &priv->accel_setting); + g_object_set_property(G_OBJECT(settings), "gtk-menu-bar-accel", &empty); - /* This stops global accelerators like Ctrl+Q == Quit */ - for (accels = priv->accel_list ; accels ; accels = accels->next) { - gtk_window_remove_accel_group(GTK_WINDOW(priv->window), accels->data); - } + /* This stops global accelerators like Ctrl+Q == Quit */ + for (accels = priv->accel_list ; accels ; accels = accels->next) { + gtk_window_remove_accel_group(GTK_WINDOW(priv->window), accels->data); + } - /* This stops menu bar shortcuts like Alt+F == File */ - for (i = 0 ; i < LAST_MENU ; i++) { - GtkWidget *menu = GTK_WIDGET(gtk_builder_get_object(priv->builder, menuNames[i])); - priv->accel_menu_sig[i] = - g_signal_connect(menu, "mnemonic-activate", - G_CALLBACK(virt_viewer_window_ignore_accel), self); - } + /* This stops menu bar shortcuts like Alt+F == File */ + for (i = 0 ; i < LAST_MENU ; i++) { + GtkWidget *menu = GTK_WIDGET(gtk_builder_get_object(priv->builder, menuNames[i])); + priv->accel_menu_sig[i] = + g_signal_connect(menu, "mnemonic-activate", + G_CALLBACK(virt_viewer_window_ignore_accel), self); + } - priv->accel_enabled = FALSE; + priv->accel_enabled = FALSE; } void virt_viewer_window_enable_modifiers(VirtViewerWindow *self) { - GtkSettings *settings = gtk_settings_get_default(); - VirtViewerWindowPrivate *priv = self->priv; - GSList *accels; - int i; + GtkSettings *settings = gtk_settings_get_default(); + VirtViewerWindowPrivate *priv = self->priv; + GSList *accels; + int i; - if (!priv->window) - return; + if (!priv->window) + return; - if (priv->accel_enabled) - return; + if (priv->accel_enabled) + return; - /* This allows F10 activating menu bar */ - g_object_set_property(G_OBJECT(settings), "gtk-menu-bar-accel", &priv->accel_setting); + /* This allows F10 activating menu bar */ + g_object_set_property(G_OBJECT(settings), "gtk-menu-bar-accel", &priv->accel_setting); - /* This allows global accelerators like Ctrl+Q == Quit */ - for (accels = priv->accel_list ; accels ; accels = accels->next) { - gtk_window_add_accel_group(GTK_WINDOW(priv->window), accels->data); - } + /* This allows global accelerators like Ctrl+Q == Quit */ + for (accels = priv->accel_list ; accels ; accels = accels->next) { + gtk_window_add_accel_group(GTK_WINDOW(priv->window), accels->data); + } - /* This allows menu bar shortcuts like Alt+F == File */ - for (i = 0 ; i < LAST_MENU ; i++) { - GtkWidget *menu = GTK_WIDGET(gtk_builder_get_object(priv->builder, menuNames[i])); - g_signal_handler_disconnect(menu, priv->accel_menu_sig[i]); - } + /* This allows menu bar shortcuts like Alt+F == File */ + for (i = 0 ; i < LAST_MENU ; i++) { + GtkWidget *menu = GTK_WIDGET(gtk_builder_get_object(priv->builder, menuNames[i])); + g_signal_handler_disconnect(menu, priv->accel_menu_sig[i]); + } - priv->accel_enabled = TRUE; + priv->accel_enabled = TRUE; } G_MODULE_EXPORT gboolean virt_viewer_window_delete(GtkWidget *src G_GNUC_UNUSED, - void *dummy G_GNUC_UNUSED, - VirtViewerWindow *self) + void *dummy G_GNUC_UNUSED, + VirtViewerWindow *self) { - virt_viewer_app_window_set_visible(self->priv->app, self, FALSE); - return TRUE; + virt_viewer_app_window_set_visible(self->priv->app, self, FALSE); + return TRUE; } G_MODULE_EXPORT void virt_viewer_window_menu_file_quit(GtkWidget *src G_GNUC_UNUSED, - VirtViewerWindow *self) + VirtViewerWindow *self) { - virt_viewer_app_quit(self->priv->app); + virt_viewer_app_quit(self->priv->app); } static void virt_viewer_window_toolbar_leave_fullscreen(GtkWidget *button G_GNUC_UNUSED, - VirtViewerWindow *self) + VirtViewerWindow *self) { - g_object_set(self->priv->app, "fullscreen", FALSE, NULL); + g_object_set(self->priv->app, "fullscreen", FALSE, NULL); } G_MODULE_EXPORT void virt_viewer_window_menu_view_fullscreen(GtkWidget *menu, - VirtViewerWindow *self) + VirtViewerWindow *self) { - gboolean fullscreen = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu)); + gboolean fullscreen = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu)); - g_object_set(self->priv->app, "fullscreen", fullscreen, NULL); + g_object_set(self->priv->app, "fullscreen", fullscreen, NULL); } G_MODULE_EXPORT void virt_viewer_window_menu_view_resize(GtkWidget *menu, - VirtViewerWindow *self) + VirtViewerWindow *self) { - VirtViewerWindowPrivate *priv = self->priv; + VirtViewerWindowPrivate *priv = self->priv; - if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu))) { - priv->auto_resize = TRUE; - if (!priv->fullscreen) - virt_viewer_window_resize(self); - } else { - priv->auto_resize = FALSE; - } + if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu))) { + priv->auto_resize = TRUE; + if (!priv->fullscreen) + virt_viewer_window_resize(self); + } else { + priv->auto_resize = FALSE; + } } static void virt_viewer_window_save_screenshot(VirtViewerWindow *self, - const char *file) + const char *file) { - VirtViewerWindowPrivate *priv = self->priv; - GdkPixbuf *pix = virt_viewer_display_get_pixbuf(VIRT_VIEWER_DISPLAY(priv->display)); + VirtViewerWindowPrivate *priv = self->priv; + GdkPixbuf *pix = virt_viewer_display_get_pixbuf(VIRT_VIEWER_DISPLAY(priv->display)); - gdk_pixbuf_save(pix, file, "png", NULL, - "tEXt::Generator App", PACKAGE, NULL); - g_object_unref(pix); + gdk_pixbuf_save(pix, file, "png", NULL, + "tEXt::Generator App", PACKAGE, NULL); + g_object_unref(pix); } G_MODULE_EXPORT void virt_viewer_window_menu_file_screenshot(GtkWidget *menu G_GNUC_UNUSED, - VirtViewerWindow *self) + VirtViewerWindow *self) { - GtkWidget *dialog; - VirtViewerWindowPrivate *priv = self->priv; + GtkWidget *dialog; + VirtViewerWindowPrivate *priv = self->priv; - g_return_if_fail(priv->display != NULL); + g_return_if_fail(priv->display != NULL); - dialog = gtk_file_chooser_dialog_new ("Save screenshot", - NULL, - GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, - NULL); - gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE); + dialog = gtk_file_chooser_dialog_new ("Save screenshot", + NULL, + GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, + NULL); + gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE); - //gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), default_folder_for_saving); - //gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "Screenshot"); + //gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), default_folder_for_saving); + //gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "Screenshot"); - if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { - char *filename; + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { + char *filename; - filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); - virt_viewer_window_save_screenshot(self, filename); - g_free (filename); - } + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); + virt_viewer_window_save_screenshot(self, filename); + g_free (filename); + } - gtk_widget_destroy (dialog); + gtk_widget_destroy (dialog); } G_MODULE_EXPORT void virt_viewer_window_menu_file_usb_device_selection(GtkWidget *menu G_GNUC_UNUSED, - VirtViewerWindow *self) + VirtViewerWindow *self) { - virt_viewer_app_usb_device_selection(self->priv->app, - GTK_WINDOW(self->priv->window)); + virt_viewer_app_usb_device_selection(self->priv->app, + GTK_WINDOW(self->priv->window)); } G_MODULE_EXPORT void virt_viewer_window_menu_help_about(GtkWidget *menu G_GNUC_UNUSED, - VirtViewerWindow *self) + VirtViewerWindow *self) { - GtkBuilder *about = virt_viewer_util_load_ui("virt-viewer-about.xml"); + GtkBuilder *about = virt_viewer_util_load_ui("virt-viewer-about.xml"); - GtkWidget *dialog = GTK_WIDGET(gtk_builder_get_object(about, "about")); - gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog), VERSION); + GtkWidget *dialog = GTK_WIDGET(gtk_builder_get_object(about, "about")); + gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog), VERSION); - gtk_builder_connect_signals(about, self); + gtk_builder_connect_signals(about, self); - gtk_widget_show_all(dialog); + gtk_widget_show_all(dialog); - g_object_unref(G_OBJECT(about)); + g_object_unref(G_OBJECT(about)); } static void virt_viewer_window_toolbar_setup(VirtViewerWindow *self) { - GtkWidget *button; - VirtViewerWindowPrivate *priv = self->priv; - - priv->toolbar = gtk_toolbar_new(); - gtk_toolbar_set_show_arrow(GTK_TOOLBAR(priv->toolbar), FALSE); - gtk_widget_set_no_show_all(priv->toolbar, TRUE); - gtk_toolbar_set_style(GTK_TOOLBAR(priv->toolbar), GTK_TOOLBAR_BOTH_HORIZ); - - /* Close connection */ - button = GTK_WIDGET(gtk_tool_button_new_from_stock(GTK_STOCK_CLOSE)); - gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(button), _("Disconnect")); - gtk_widget_show(GTK_WIDGET(button)); - gtk_toolbar_insert(GTK_TOOLBAR(priv->toolbar), GTK_TOOL_ITEM (button), 0); - g_signal_connect(button, "clicked", G_CALLBACK(gtk_main_quit), NULL); - - /* Leave fullscreen */ - button = GTK_WIDGET(gtk_tool_button_new_from_stock(GTK_STOCK_LEAVE_FULLSCREEN)); - gtk_tool_button_set_label(GTK_TOOL_BUTTON(button), _("Leave fullscreen")); - gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(button), _("Leave fullscreen")); - gtk_tool_item_set_is_important(GTK_TOOL_ITEM(button), TRUE); - gtk_widget_show(GTK_WIDGET(button)); - gtk_toolbar_insert(GTK_TOOLBAR(priv->toolbar), GTK_TOOL_ITEM(button), 0); - g_signal_connect(button, "clicked", G_CALLBACK(virt_viewer_window_toolbar_leave_fullscreen), self); - - priv->layout = ViewAutoDrawer_New(); - - ViewAutoDrawer_SetActive(VIEW_AUTODRAWER(priv->layout), FALSE); - ViewOvBox_SetOver(VIEW_OV_BOX(priv->layout), priv->toolbar); - ViewOvBox_SetUnder(VIEW_OV_BOX(priv->layout), GTK_WIDGET(priv->notebook)); - ViewAutoDrawer_SetOffset(VIEW_AUTODRAWER(priv->layout), -1); - ViewAutoDrawer_SetFill(VIEW_AUTODRAWER(priv->layout), FALSE); - ViewAutoDrawer_SetOverlapPixels(VIEW_AUTODRAWER(priv->layout), 1); - ViewAutoDrawer_SetNoOverlapPixels(VIEW_AUTODRAWER(priv->layout), 0); - gtk_widget_show(priv->layout); + GtkWidget *button; + VirtViewerWindowPrivate *priv = self->priv; + + priv->toolbar = gtk_toolbar_new(); + gtk_toolbar_set_show_arrow(GTK_TOOLBAR(priv->toolbar), FALSE); + gtk_widget_set_no_show_all(priv->toolbar, TRUE); + gtk_toolbar_set_style(GTK_TOOLBAR(priv->toolbar), GTK_TOOLBAR_BOTH_HORIZ); + + /* Close connection */ + button = GTK_WIDGET(gtk_tool_button_new_from_stock(GTK_STOCK_CLOSE)); + gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(button), _("Disconnect")); + gtk_widget_show(GTK_WIDGET(button)); + gtk_toolbar_insert(GTK_TOOLBAR(priv->toolbar), GTK_TOOL_ITEM (button), 0); + g_signal_connect(button, "clicked", G_CALLBACK(gtk_main_quit), NULL); + + /* Leave fullscreen */ + button = GTK_WIDGET(gtk_tool_button_new_from_stock(GTK_STOCK_LEAVE_FULLSCREEN)); + gtk_tool_button_set_label(GTK_TOOL_BUTTON(button), _("Leave fullscreen")); + gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(button), _("Leave fullscreen")); + gtk_tool_item_set_is_important(GTK_TOOL_ITEM(button), TRUE); + gtk_widget_show(GTK_WIDGET(button)); + gtk_toolbar_insert(GTK_TOOLBAR(priv->toolbar), GTK_TOOL_ITEM(button), 0); + g_signal_connect(button, "clicked", G_CALLBACK(virt_viewer_window_toolbar_leave_fullscreen), self); + + priv->layout = ViewAutoDrawer_New(); + + ViewAutoDrawer_SetActive(VIEW_AUTODRAWER(priv->layout), FALSE); + ViewOvBox_SetOver(VIEW_OV_BOX(priv->layout), priv->toolbar); + ViewOvBox_SetUnder(VIEW_OV_BOX(priv->layout), GTK_WIDGET(priv->notebook)); + ViewAutoDrawer_SetOffset(VIEW_AUTODRAWER(priv->layout), -1); + ViewAutoDrawer_SetFill(VIEW_AUTODRAWER(priv->layout), FALSE); + ViewAutoDrawer_SetOverlapPixels(VIEW_AUTODRAWER(priv->layout), 1); + ViewAutoDrawer_SetNoOverlapPixels(VIEW_AUTODRAWER(priv->layout), 0); + gtk_widget_show(priv->layout); } VirtViewerNotebook* virt_viewer_window_get_notebook (VirtViewerWindow *self) { - return VIRT_VIEWER_NOTEBOOK(self->priv->notebook); + return VIRT_VIEWER_NOTEBOOK(self->priv->notebook); } GtkWindow* virt_viewer_window_get_window (VirtViewerWindow *self) { - return GTK_WINDOW(self->priv->window); + return GTK_WINDOW(self->priv->window); } static void virt_viewer_window_pointer_grab(VirtViewerDisplay *display G_GNUC_UNUSED, - VirtViewerWindow *self) + VirtViewerWindow *self) { - VirtViewerWindowPrivate *priv = self->priv; + VirtViewerWindowPrivate *priv = self->priv; - priv->grabbed = TRUE; - virt_viewer_window_update_title(self); + priv->grabbed = TRUE; + virt_viewer_window_update_title(self); } static void virt_viewer_window_pointer_ungrab(VirtViewerDisplay *display G_GNUC_UNUSED, - VirtViewerWindow *self) + VirtViewerWindow *self) { - VirtViewerWindowPrivate *priv = self->priv; + VirtViewerWindowPrivate *priv = self->priv; - priv->grabbed = FALSE; - virt_viewer_window_update_title(self); + priv->grabbed = FALSE; + virt_viewer_window_update_title(self); } static void virt_viewer_window_keyboard_grab(VirtViewerDisplay *display G_GNUC_UNUSED, - VirtViewerWindow *self) + VirtViewerWindow *self) { - virt_viewer_window_disable_modifiers(self); + virt_viewer_window_disable_modifiers(self); } static void virt_viewer_window_keyboard_ungrab(VirtViewerDisplay *display G_GNUC_UNUSED, - VirtViewerWindow *self) + VirtViewerWindow *self) { - virt_viewer_window_enable_modifiers(self); + virt_viewer_window_enable_modifiers(self); } void virt_viewer_window_update_title(VirtViewerWindow *self) { - VirtViewerWindowPrivate *priv = self->priv; - char *title; - const char *ungrab = NULL; + VirtViewerWindowPrivate *priv = self->priv; + char *title; + const char *ungrab = NULL; - if (priv->grabbed) - ungrab = _("(Press Ctrl+Alt to release pointer)"); + if (priv->grabbed) + ungrab = _("(Press Ctrl+Alt to release pointer)"); - if (!ungrab && !priv->subtitle) - title = g_strdup(g_get_application_name()); - else - /* translators: - * This is "<ungrab (or empty)><space (or empty)><subtitle (or empty)> - <appname>" - * Such as: "(Press Ctrl+Alt to release pointer) BigCorpTycoon MOTD - Virt Viewer" - */ - title = g_strdup_printf(_("%s%s%s - %s"), - /* translators: <ungrab empty> */ - ungrab ? ungrab : _(""), - /* translators: <space> */ - ungrab && priv->subtitle ? _(" ") : _(""), - priv->subtitle, - g_get_application_name()); + if (!ungrab && !priv->subtitle) + title = g_strdup(g_get_application_name()); + else + /* translators: + * This is "<ungrab (or empty)><space (or empty)><subtitle (or empty)> - <appname>" + * Such as: "(Press Ctrl+Alt to release pointer) BigCorpTycoon MOTD - Virt Viewer" + */ + title = g_strdup_printf(_("%s%s%s - %s"), + /* translators: <ungrab empty> */ + ungrab ? ungrab : _(""), + /* translators: <space> */ + ungrab && priv->subtitle ? _(" ") : _(""), + priv->subtitle, + g_get_application_name()); - gtk_window_set_title(GTK_WINDOW(priv->window), title); + gtk_window_set_title(GTK_WINDOW(priv->window), title); - g_free(title); + g_free(title); } void virt_viewer_window_set_usb_options_sensitive(VirtViewerWindow *self, gboolean sensitive) { - VirtViewerWindowPrivate *priv; - GtkWidget *menu; + VirtViewerWindowPrivate *priv; + GtkWidget *menu; - g_return_if_fail(VIRT_VIEWER_IS_WINDOW(self)); + g_return_if_fail(VIRT_VIEWER_IS_WINDOW(self)); - priv = self->priv; - menu = GTK_WIDGET(gtk_builder_get_object(priv->builder, "menu-file-usb-device-selection")); - gtk_widget_set_sensitive(menu, sensitive); + priv = self->priv; + menu = GTK_WIDGET(gtk_builder_get_object(priv->builder, "menu-file-usb-device-selection")); + gtk_widget_set_sensitive(menu, sensitive); } void virt_viewer_window_set_display(VirtViewerWindow *self, VirtViewerDisplay *display) { - VirtViewerWindowPrivate *priv; + VirtViewerWindowPrivate *priv; - g_return_if_fail(VIRT_VIEWER_IS_WINDOW(self)); - g_return_if_fail(display == NULL || VIRT_VIEWER_IS_DISPLAY(display)); + g_return_if_fail(VIRT_VIEWER_IS_WINDOW(self)); + g_return_if_fail(display == NULL || VIRT_VIEWER_IS_DISPLAY(display)); - priv = self->priv; - if (priv->display) { - gtk_notebook_remove_page(GTK_NOTEBOOK(priv->notebook), 1); - g_object_unref(priv->display); - priv->display = NULL; - } + priv = self->priv; + if (priv->display) { + gtk_notebook_remove_page(GTK_NOTEBOOK(priv->notebook), 1); + g_object_unref(priv->display); + priv->display = NULL; + } - if (display != NULL) { - priv->display = g_object_ref(display); + if (display != NULL) { + priv->display = g_object_ref(display); - virt_viewer_display_set_zoom_level(VIRT_VIEWER_DISPLAY(priv->display), priv->zoomlevel); + virt_viewer_display_set_zoom_level(VIRT_VIEWER_DISPLAY(priv->display), priv->zoomlevel); - gtk_notebook_append_page(GTK_NOTEBOOK(priv->notebook), GTK_WIDGET(display), NULL); - gtk_widget_show_all(GTK_WIDGET(display)); + gtk_notebook_append_page(GTK_NOTEBOOK(priv->notebook), GTK_WIDGET(display), NULL); + gtk_widget_show_all(GTK_WIDGET(display)); - g_signal_connect(display, "display-pointer-grab", - G_CALLBACK(virt_viewer_window_pointer_grab), self); - g_signal_connect(display, "display-pointer-ungrab", - G_CALLBACK(virt_viewer_window_pointer_ungrab), self); - g_signal_connect(display, "display-keyboard-grab", - G_CALLBACK(virt_viewer_window_keyboard_grab), self); - g_signal_connect(display, "display-keyboard-ungrab", - G_CALLBACK(virt_viewer_window_keyboard_ungrab), self); - g_signal_connect(display, "display-desktop-resize", - G_CALLBACK(virt_viewer_window_desktop_resize), self); - } + g_signal_connect(display, "display-pointer-grab", + G_CALLBACK(virt_viewer_window_pointer_grab), self); + g_signal_connect(display, "display-pointer-ungrab", + G_CALLBACK(virt_viewer_window_pointer_ungrab), self); + g_signal_connect(display, "display-keyboard-grab", + G_CALLBACK(virt_viewer_window_keyboard_grab), self); + g_signal_connect(display, "display-keyboard-ungrab", + G_CALLBACK(virt_viewer_window_keyboard_ungrab), self); + g_signal_connect(display, "display-desktop-resize", + G_CALLBACK(virt_viewer_window_desktop_resize), self); + } } void virt_viewer_window_set_zoom_level(VirtViewerWindow *self, gint zoom_level) { - g_return_if_fail(VIRT_VIEWER_IS_WINDOW(self)); + g_return_if_fail(VIRT_VIEWER_IS_WINDOW(self)); - /* FIXME: turn into a dynamic property */ - self->priv->zoomlevel = zoom_level; + /* FIXME: turn into a dynamic property */ + self->priv->zoomlevel = zoom_level; } gint virt_viewer_window_get_zoom_level(VirtViewerWindow *self) { - g_return_val_if_fail(VIRT_VIEWER_IS_WINDOW(self), 100); - return self->priv->zoomlevel; + g_return_val_if_fail(VIRT_VIEWER_IS_WINDOW(self), 100); + return self->priv->zoomlevel; } GtkMenuItem* virt_viewer_window_get_menu_displays(VirtViewerWindow *self) { - g_return_val_if_fail(VIRT_VIEWER_IS_WINDOW(self), NULL); + g_return_val_if_fail(VIRT_VIEWER_IS_WINDOW(self), NULL); - return GTK_MENU_ITEM(gtk_builder_get_object(self->priv->builder, "menu-displays")); + return GTK_MENU_ITEM(gtk_builder_get_object(self->priv->builder, "menu-displays")); } GtkBuilder* virt_viewer_window_get_builder(VirtViewerWindow *self) { - g_return_val_if_fail(VIRT_VIEWER_IS_WINDOW(self), NULL); + g_return_val_if_fail(VIRT_VIEWER_IS_WINDOW(self), NULL); - return self->priv->builder; + return self->priv->builder; } /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 - * indent-tabs-mode: t + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/virt-viewer-window.h b/src/virt-viewer-window.h index e5c184f..4db3757 100644 --- a/src/virt-viewer-window.h +++ b/src/virt-viewer-window.h @@ -32,30 +32,30 @@ G_BEGIN_DECLS #define VIRT_VIEWER_TYPE_WINDOW virt_viewer_window_get_type() -#define VIRT_VIEWER_WINDOW(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIRT_VIEWER_TYPE_WINDOW, VirtViewerWindow)) +#define VIRT_VIEWER_WINDOW(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIRT_VIEWER_TYPE_WINDOW, VirtViewerWindow)) -#define VIRT_VIEWER_WINDOW_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), VIRT_VIEWER_TYPE_WINDOW, VirtViewerWindowClass)) +#define VIRT_VIEWER_WINDOW_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), VIRT_VIEWER_TYPE_WINDOW, VirtViewerWindowClass)) -#define VIRT_VIEWER_IS_WINDOW(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIRT_VIEWER_TYPE_WINDOW)) +#define VIRT_VIEWER_IS_WINDOW(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIRT_VIEWER_TYPE_WINDOW)) -#define VIRT_VIEWER_IS_WINDOW_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), VIRT_VIEWER_TYPE_WINDOW)) +#define VIRT_VIEWER_IS_WINDOW_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), VIRT_VIEWER_TYPE_WINDOW)) -#define VIRT_VIEWER_WINDOW_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), VIRT_VIEWER_TYPE_WINDOW, VirtViewerWindowClass)) +#define VIRT_VIEWER_WINDOW_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), VIRT_VIEWER_TYPE_WINDOW, VirtViewerWindowClass)) typedef struct _VirtViewerWindowPrivate VirtViewerWindowPrivate; typedef struct { - GObject parent; - VirtViewerWindowPrivate *priv; + GObject parent; + VirtViewerWindowPrivate *priv; } VirtViewerWindow; typedef struct { - GObjectClass parent_class; + GObjectClass parent_class; } VirtViewerWindowClass; GType virt_viewer_window_get_type (void); @@ -75,11 +75,11 @@ GtkBuilder* virt_viewer_window_get_builder(VirtViewerWindow *window); G_END_DECLS #endif /* _VIRT_VIEWER_WINDOW */ + /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 - * indent-tabs-mode: t + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/virt-viewer.c b/src/virt-viewer.c index 9dc0ad8..31c4dd9 100644 --- a/src/virt-viewer.c +++ b/src/virt-viewer.c @@ -50,18 +50,18 @@ #include "virt-viewer-auth.h" struct _VirtViewerPrivate { - char *uri; - virConnectPtr conn; - virDomainPtr dom; - char *domkey; - gboolean withEvents; - gboolean waitvm; - gboolean reconnect; + char *uri; + virConnectPtr conn; + virDomainPtr dom; + char *domkey; + gboolean withEvents; + gboolean waitvm; + gboolean reconnect; }; G_DEFINE_TYPE (VirtViewer, virt_viewer, VIRT_VIEWER_TYPE_APP) -#define GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), VIRT_VIEWER_TYPE, VirtViewerPrivate)) +#define GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), VIRT_VIEWER_TYPE, VirtViewerPrivate)) static int virt_viewer_initial_connect(VirtViewerApp *self); static gboolean virt_viewer_open_connection(VirtViewerApp *self, int *fd); @@ -70,563 +70,562 @@ static gboolean virt_viewer_start(VirtViewerApp *self); static void virt_viewer_get_property (GObject *object, guint property_id, - GValue *value G_GNUC_UNUSED, GParamSpec *pspec) + GValue *value G_GNUC_UNUSED, GParamSpec *pspec) { - switch (property_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } + switch (property_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } } static void virt_viewer_set_property (GObject *object, guint property_id, - const GValue *value G_GNUC_UNUSED, GParamSpec *pspec) + const GValue *value G_GNUC_UNUSED, GParamSpec *pspec) { - switch (property_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } + switch (property_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } } static void virt_viewer_dispose (GObject *object) { - VirtViewer *self = VIRT_VIEWER(object); - VirtViewerPrivate *priv = self->priv; - if (priv->dom) - virDomainFree(priv->dom); - if (priv->conn) - virConnectClose(priv->conn); - G_OBJECT_CLASS(virt_viewer_parent_class)->dispose (object); + VirtViewer *self = VIRT_VIEWER(object); + VirtViewerPrivate *priv = self->priv; + if (priv->dom) + virDomainFree(priv->dom); + if (priv->conn) + virConnectClose(priv->conn); + G_OBJECT_CLASS(virt_viewer_parent_class)->dispose (object); } static void virt_viewer_class_init (VirtViewerClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - VirtViewerAppClass *app_class = VIRT_VIEWER_APP_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + VirtViewerAppClass *app_class = VIRT_VIEWER_APP_CLASS (klass); - g_type_class_add_private (klass, sizeof (VirtViewerPrivate)); + g_type_class_add_private (klass, sizeof (VirtViewerPrivate)); - object_class->get_property = virt_viewer_get_property; - object_class->set_property = virt_viewer_set_property; - object_class->dispose = virt_viewer_dispose; + object_class->get_property = virt_viewer_get_property; + object_class->set_property = virt_viewer_set_property; + object_class->dispose = virt_viewer_dispose; - app_class->initial_connect = virt_viewer_initial_connect; - app_class->deactivated = virt_viewer_deactivated; - app_class->open_connection = virt_viewer_open_connection; - app_class->start = virt_viewer_start; + app_class->initial_connect = virt_viewer_initial_connect; + app_class->deactivated = virt_viewer_deactivated; + app_class->open_connection = virt_viewer_open_connection; + app_class->start = virt_viewer_start; } static void virt_viewer_init(VirtViewer *self) { - self->priv = GET_PRIVATE(self); + self->priv = GET_PRIVATE(self); } static void virt_viewer_deactivated(VirtViewerApp *app) { - VirtViewer *self = VIRT_VIEWER(app); - VirtViewerPrivate *priv = self->priv; - - if (priv->dom) { - virDomainFree(priv->dom); - priv->dom = NULL; - } - - if (priv->reconnect) { - if (!priv->withEvents) { - DEBUG_LOG("No domain events, falling back to polling"); - virt_viewer_app_start_reconnect_poll(app); - } - - virt_viewer_app_show_status(app, _("Waiting for guest domain to re-start")); - virt_viewer_app_trace(app, "Guest %s display has disconnected, waiting to reconnect", priv->domkey); - } else { - VIRT_VIEWER_APP_CLASS(virt_viewer_parent_class)->deactivated(app); - } + VirtViewer *self = VIRT_VIEWER(app); + VirtViewerPrivate *priv = self->priv; + + if (priv->dom) { + virDomainFree(priv->dom); + priv->dom = NULL; + } + + if (priv->reconnect) { + if (!priv->withEvents) { + DEBUG_LOG("No domain events, falling back to polling"); + virt_viewer_app_start_reconnect_poll(app); + } + + virt_viewer_app_show_status(app, _("Waiting for guest domain to re-start")); + virt_viewer_app_trace(app, "Guest %s display has disconnected, waiting to reconnect", priv->domkey); + } else { + VIRT_VIEWER_APP_CLASS(virt_viewer_parent_class)->deactivated(app); + } } static int virt_viewer_parse_uuid(const char *name, - unsigned char *uuid) + unsigned char *uuid) { - int i; - - const char *cur = name; - for (i = 0;i < 16;) { - uuid[i] = 0; - if (*cur == 0) - return -1; - if ((*cur == '-') || (*cur == ' ')) { - cur++; - continue; - } - if ((*cur >= '0') && (*cur <= '9')) - uuid[i] = *cur - '0'; - else if ((*cur >= 'a') && (*cur <= 'f')) - uuid[i] = *cur - 'a' + 10; - else if ((*cur >= 'A') && (*cur <= 'F')) - uuid[i] = *cur - 'A' + 10; - else - return -1; - uuid[i] *= 16; - cur++; - if (*cur == 0) - return -1; - if ((*cur >= '0') && (*cur <= '9')) - uuid[i] += *cur - '0'; - else if ((*cur >= 'a') && (*cur <= 'f')) - uuid[i] += *cur - 'a' + 10; - else if ((*cur >= 'A') && (*cur <= 'F')) - uuid[i] += *cur - 'A' + 10; - else - return -1; - i++; - cur++; - } - - return 0; + int i; + + const char *cur = name; + for (i = 0;i < 16;) { + uuid[i] = 0; + if (*cur == 0) + return -1; + if ((*cur == '-') || (*cur == ' ')) { + cur++; + continue; + } + if ((*cur >= '0') && (*cur <= '9')) + uuid[i] = *cur - '0'; + else if ((*cur >= 'a') && (*cur <= 'f')) + uuid[i] = *cur - 'a' + 10; + else if ((*cur >= 'A') && (*cur <= 'F')) + uuid[i] = *cur - 'A' + 10; + else + return -1; + uuid[i] *= 16; + cur++; + if (*cur == 0) + return -1; + if ((*cur >= '0') && (*cur <= '9')) + uuid[i] += *cur - '0'; + else if ((*cur >= 'a') && (*cur <= 'f')) + uuid[i] += *cur - 'a' + 10; + else if ((*cur >= 'A') && (*cur <= 'F')) + uuid[i] += *cur - 'A' + 10; + else + return -1; + i++; + cur++; + } + + return 0; } static virDomainPtr virt_viewer_lookup_domain(VirtViewer *self) { - char *end; - VirtViewerPrivate *priv = self->priv; - int id = strtol(priv->domkey, &end, 10); - virDomainPtr dom = NULL; - unsigned char uuid[16]; - - if (id >= 0 && end && !*end) { - dom = virDomainLookupByID(priv->conn, id); - } - if (!dom && virt_viewer_parse_uuid(priv->domkey, uuid) == 0) { - dom = virDomainLookupByUUID(priv->conn, uuid); - } - if (!dom) { - dom = virDomainLookupByName(priv->conn, priv->domkey); - } - return dom; + char *end; + VirtViewerPrivate *priv = self->priv; + int id = strtol(priv->domkey, &end, 10); + virDomainPtr dom = NULL; + unsigned char uuid[16]; + + if (id >= 0 && end && !*end) { + dom = virDomainLookupByID(priv->conn, id); + } + if (!dom && virt_viewer_parse_uuid(priv->domkey, uuid) == 0) { + dom = virDomainLookupByUUID(priv->conn, uuid); + } + if (!dom) { + dom = virDomainLookupByName(priv->conn, priv->domkey); + } + return dom; } static int virt_viewer_matches_domain(VirtViewer *self, - virDomainPtr dom) + virDomainPtr dom) { - char *end; - const char *name; - VirtViewerPrivate *priv = self->priv; - int id = strtol(priv->domkey, &end, 10); - unsigned char wantuuid[16]; - unsigned char domuuid[16]; - - if (id >= 0 && end && !*end) { - if (virDomainGetID(dom) == id) - return 1; - } - if (virt_viewer_parse_uuid(priv->domkey, wantuuid) == 0) { - virDomainGetUUID(dom, domuuid); - if (memcmp(wantuuid, domuuid, VIR_UUID_BUFLEN) == 0) - return 1; - } - - name = virDomainGetName(dom); - if (strcmp(name, priv->domkey) == 0) - return 1; - - return 0; + char *end; + const char *name; + VirtViewerPrivate *priv = self->priv; + int id = strtol(priv->domkey, &end, 10); + unsigned char wantuuid[16]; + unsigned char domuuid[16]; + + if (id >= 0 && end && !*end) { + if (virDomainGetID(dom) == id) + return 1; + } + if (virt_viewer_parse_uuid(priv->domkey, wantuuid) == 0) { + virDomainGetUUID(dom, domuuid); + if (memcmp(wantuuid, domuuid, VIR_UUID_BUFLEN) == 0) + return 1; + } + + name = virDomainGetName(dom); + if (strcmp(name, priv->domkey) == 0) + return 1; + + return 0; } static char * virt_viewer_extract_xpath_string(const gchar *xmldesc, - const gchar *xpath) + const gchar *xpath) { - xmlDocPtr xml = NULL; - xmlParserCtxtPtr pctxt = NULL; - xmlXPathContextPtr ctxt = NULL; - xmlXPathObjectPtr obj = NULL; - char *port = NULL; - - pctxt = xmlNewParserCtxt(); - if (!pctxt || !pctxt->sax) - goto error; - - xml = xmlCtxtReadDoc(pctxt, (const xmlChar *)xmldesc, "domain.xml", NULL, - XML_PARSE_NOENT | XML_PARSE_NONET | - XML_PARSE_NOWARNING); - if (!xml) - goto error; - - ctxt = xmlXPathNewContext(xml); - if (!ctxt) - goto error; - - obj = xmlXPathEval((const xmlChar *)xpath, ctxt); - if (!obj || obj->type != XPATH_STRING || !obj->stringval || !obj->stringval[0]) - goto error; - if (!strcmp((const char*)obj->stringval, "-1")) - goto error; - - port = g_strdup((const char*)obj->stringval); - xmlXPathFreeObject(obj); - obj = NULL; + xmlDocPtr xml = NULL; + xmlParserCtxtPtr pctxt = NULL; + xmlXPathContextPtr ctxt = NULL; + xmlXPathObjectPtr obj = NULL; + char *port = NULL; + + pctxt = xmlNewParserCtxt(); + if (!pctxt || !pctxt->sax) + goto error; + + xml = xmlCtxtReadDoc(pctxt, (const xmlChar *)xmldesc, "domain.xml", NULL, + XML_PARSE_NOENT | XML_PARSE_NONET | + XML_PARSE_NOWARNING); + if (!xml) + goto error; + + ctxt = xmlXPathNewContext(xml); + if (!ctxt) + goto error; + + obj = xmlXPathEval((const xmlChar *)xpath, ctxt); + if (!obj || obj->type != XPATH_STRING || !obj->stringval || !obj->stringval[0]) + goto error; + if (!strcmp((const char*)obj->stringval, "-1")) + goto error; + + port = g_strdup((const char*)obj->stringval); + xmlXPathFreeObject(obj); + obj = NULL; error: - if (obj) - xmlXPathFreeObject(obj); - if (ctxt) - xmlXPathFreeContext(ctxt); - if (xml) - xmlFreeDoc(xml); - if (pctxt) - xmlFreeParserCtxt(pctxt); - return port; + if (obj) + xmlXPathFreeObject(obj); + if (ctxt) + xmlXPathFreeContext(ctxt); + if (xml) + xmlFreeDoc(xml); + if (pctxt) + xmlFreeParserCtxt(pctxt); + return port; } static gboolean virt_viewer_extract_connect_info(VirtViewer *self, - virDomainPtr dom) + virDomainPtr dom) { - char *type = NULL; - char *xpath = NULL; - gboolean retval = FALSE; - char *xmldesc = virDomainGetXMLDesc(dom, 0); - VirtViewerPrivate *priv = self->priv; - VirtViewerApp *app = VIRT_VIEWER_APP(self); - gchar *gport = NULL; - gchar *ghost = NULL; - gchar *unixsock = NULL; - gchar *host = NULL; - gchar *transport = NULL; - gchar *user = NULL; - gint port = 0; - gchar *uri = NULL; - - virt_viewer_app_free_connect_info(app); - - if ((type = virt_viewer_extract_xpath_string(xmldesc, "string(/domain/devices/graphics/@type)")) == NULL) { - virt_viewer_app_simple_message_dialog(app, _("Cannot determine the graphic type for the guest %s"), - priv->domkey); - goto cleanup; - } - - if (virt_viewer_app_create_session(app, type) < 0) - goto cleanup; - - xpath = g_strdup_printf("string(/domain/devices/graphics[@type='%s']/@port)", type); - if ((gport = virt_viewer_extract_xpath_string(xmldesc, xpath)) == NULL) { - free(xpath); - xpath = g_strdup_printf("string(/domain/devices/graphics[@type='%s']/@socket)", type); - if ((unixsock = virt_viewer_extract_xpath_string(xmldesc, xpath)) == NULL) { - virt_viewer_app_simple_message_dialog(app, _("Cannot determine the graphic address for the guest %s"), - priv->domkey); - goto cleanup; - } - } else { - free(xpath); - xpath = g_strdup_printf("string(/domain/devices/graphics[@type='%s']/@listen)", type); - ghost = virt_viewer_extract_xpath_string(xmldesc, xpath); - if (ghost == NULL) - ghost = g_strdup("localhost"); - } - - if (ghost && gport) - DEBUG_LOG("Guest graphics address is %s:%s", ghost, gport); - else if (unixsock) - DEBUG_LOG("Guest graphics address is %s", unixsock); - - uri = virConnectGetURI(priv->conn); - if (virt_viewer_util_extract_host(uri, NULL, &host, &transport, &user, &port) < 0) { - virt_viewer_app_simple_message_dialog(app, _("Cannot determine the host for the guest %s"), - priv->domkey); - goto cleanup; - } - - /* If the XML listen attribute shows a wildcard address, we need to - * throw that away since you obviously can't 'connect(2)' to that - * from a remote host. Instead we fallback to the hostname used in - * the libvirt URI. This isn't perfect but it is better than nothing - */ - if (ghost && - (strcmp(ghost, "0.0.0.0") == 0 || - strcmp(ghost, "::") == 0)) { - DEBUG_LOG("Guest graphics listen '%s' is a wildcard, replacing with '%s'", - ghost, host); - g_free(ghost); - ghost = g_strdup(host); - } - - virt_viewer_app_set_connect_info(app, host, ghost, gport, transport, unixsock, user, port, NULL); - - retval = TRUE; + char *type = NULL; + char *xpath = NULL; + gboolean retval = FALSE; + char *xmldesc = virDomainGetXMLDesc(dom, 0); + VirtViewerPrivate *priv = self->priv; + VirtViewerApp *app = VIRT_VIEWER_APP(self); + gchar *gport = NULL; + gchar *ghost = NULL; + gchar *unixsock = NULL; + gchar *host = NULL; + gchar *transport = NULL; + gchar *user = NULL; + gint port = 0; + gchar *uri = NULL; + + virt_viewer_app_free_connect_info(app); + + if ((type = virt_viewer_extract_xpath_string(xmldesc, "string(/domain/devices/graphics/@type)")) == NULL) { + virt_viewer_app_simple_message_dialog(app, _("Cannot determine the graphic type for the guest %s"), + priv->domkey); + goto cleanup; + } + + if (virt_viewer_app_create_session(app, type) < 0) + goto cleanup; + + xpath = g_strdup_printf("string(/domain/devices/graphics[@type='%s']/@port)", type); + if ((gport = virt_viewer_extract_xpath_string(xmldesc, xpath)) == NULL) { + free(xpath); + xpath = g_strdup_printf("string(/domain/devices/graphics[@type='%s']/@socket)", type); + if ((unixsock = virt_viewer_extract_xpath_string(xmldesc, xpath)) == NULL) { + virt_viewer_app_simple_message_dialog(app, _("Cannot determine the graphic address for the guest %s"), + priv->domkey); + goto cleanup; + } + } else { + free(xpath); + xpath = g_strdup_printf("string(/domain/devices/graphics[@type='%s']/@listen)", type); + ghost = virt_viewer_extract_xpath_string(xmldesc, xpath); + if (ghost == NULL) + ghost = g_strdup("localhost"); + } + + if (ghost && gport) + DEBUG_LOG("Guest graphics address is %s:%s", ghost, gport); + else if (unixsock) + DEBUG_LOG("Guest graphics address is %s", unixsock); + + uri = virConnectGetURI(priv->conn); + if (virt_viewer_util_extract_host(uri, NULL, &host, &transport, &user, &port) < 0) { + virt_viewer_app_simple_message_dialog(app, _("Cannot determine the host for the guest %s"), + priv->domkey); + goto cleanup; + } + + /* If the XML listen attribute shows a wildcard address, we need to + * throw that away since you obviously can't 'connect(2)' to that + * from a remote host. Instead we fallback to the hostname used in + * the libvirt URI. This isn't perfect but it is better than nothing + */ + if (ghost && + (strcmp(ghost, "0.0.0.0") == 0 || + strcmp(ghost, "::") == 0)) { + DEBUG_LOG("Guest graphics listen '%s' is a wildcard, replacing with '%s'", + ghost, host); + g_free(ghost); + ghost = g_strdup(host); + } + + virt_viewer_app_set_connect_info(app, host, ghost, gport, transport, unixsock, user, port, NULL); + + retval = TRUE; cleanup: - g_free(gport); - g_free(ghost); - g_free(unixsock); - g_free(host); - g_free(transport); - g_free(user); - g_free(type); - g_free(xpath); - g_free(xmldesc); - g_free(uri); - return retval; + g_free(gport); + g_free(ghost); + g_free(unixsock); + g_free(host); + g_free(transport); + g_free(user); + g_free(type); + g_free(xpath); + g_free(xmldesc); + g_free(uri); + return retval; } static int virt_viewer_update_display(VirtViewer *self, virDomainPtr dom) { - VirtViewerPrivate *priv = self->priv; - VirtViewerApp *app = VIRT_VIEWER_APP(self); + VirtViewerPrivate *priv = self->priv; + VirtViewerApp *app = VIRT_VIEWER_APP(self); - if (priv->dom) - virDomainFree(priv->dom); - priv->dom = dom; - virDomainRef(priv->dom); + if (priv->dom) + virDomainFree(priv->dom); + priv->dom = dom; + virDomainRef(priv->dom); - virt_viewer_app_trace(app, "Guest %s is running, determining display\n", - priv->domkey); + virt_viewer_app_trace(app, "Guest %s is running, determining display\n", + priv->domkey); - g_object_set(app, "title", virDomainGetName(dom), NULL); + g_object_set(app, "title", virDomainGetName(dom), NULL); - if (!virt_viewer_app_has_session(app)) { - if (!virt_viewer_extract_connect_info(self, dom)) - return -1; - } + if (!virt_viewer_app_has_session(app)) { + if (!virt_viewer_extract_connect_info(self, dom)) + return -1; + } - return 0; + return 0; } static gboolean virt_viewer_open_connection(VirtViewerApp *self G_GNUC_UNUSED, int *fd) { #if defined(HAVE_SOCKETPAIR) - VirtViewer *viewer = VIRT_VIEWER(self); - VirtViewerPrivate *priv = viewer->priv; - int pair[2]; + VirtViewer *viewer = VIRT_VIEWER(self); + VirtViewerPrivate *priv = viewer->priv; + int pair[2]; #endif - *fd = -1; + *fd = -1; #if defined(HAVE_SOCKETPAIR) - if (!priv->dom) - return TRUE; - - if (socketpair(PF_UNIX, SOCK_STREAM, 0, pair) < 0) - return FALSE; - - if (virDomainOpenGraphics(priv->dom, 0, pair[0], - VIR_DOMAIN_OPEN_GRAPHICS_SKIPAUTH) < 0) { - virErrorPtr err = virGetLastError(); - DEBUG_LOG("Error %s", err && err->message ? err->message : "Unknown"); - close(pair[0]); - close(pair[1]); - return TRUE; - } - close(pair[0]); - *fd = pair[1]; + if (!priv->dom) + return TRUE; + + if (socketpair(PF_UNIX, SOCK_STREAM, 0, pair) < 0) + return FALSE; + + if (virDomainOpenGraphics(priv->dom, 0, pair[0], + VIR_DOMAIN_OPEN_GRAPHICS_SKIPAUTH) < 0) { + virErrorPtr err = virGetLastError(); + DEBUG_LOG("Error %s", err && err->message ? err->message : "Unknown"); + close(pair[0]); + close(pair[1]); + return TRUE; + } + close(pair[0]); + *fd = pair[1]; #endif - return TRUE; + return TRUE; } static int virt_viewer_domain_event(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - int event, - int detail G_GNUC_UNUSED, - void *opaque) + virDomainPtr dom, + int event, + int detail G_GNUC_UNUSED, + void *opaque) { - VirtViewer *self = opaque; - VirtViewerApp *app = VIRT_VIEWER_APP(self); + VirtViewer *self = opaque; + VirtViewerApp *app = VIRT_VIEWER_APP(self); - DEBUG_LOG("Got domain event %d %d", event, detail); + DEBUG_LOG("Got domain event %d %d", event, detail); - if (!virt_viewer_matches_domain(self, dom)) - return 0; + if (!virt_viewer_matches_domain(self, dom)) + return 0; - switch (event) { - case VIR_DOMAIN_EVENT_STOPPED: - //virt_viewer_deactivate(self); - break; + switch (event) { + case VIR_DOMAIN_EVENT_STOPPED: + //virt_viewer_deactivate(self); + break; - case VIR_DOMAIN_EVENT_STARTED: - virt_viewer_update_display(self, dom); - virt_viewer_app_activate(app); - break; - } + case VIR_DOMAIN_EVENT_STARTED: + virt_viewer_update_display(self, dom); + virt_viewer_app_activate(app); + break; + } - return 0; + return 0; } static int virt_viewer_initial_connect(VirtViewerApp *app) { - virDomainPtr dom = NULL; - virDomainInfo info; - int ret = -1; - VirtViewer *self = VIRT_VIEWER(app); - VirtViewerPrivate *priv = self->priv; - - virt_viewer_app_show_status(app, _("Finding guest domain")); - dom = virt_viewer_lookup_domain(self); - if (!dom) { - if (priv->waitvm) { - virt_viewer_app_show_status(app, _("Waiting for guest domain to be created")); - virt_viewer_app_trace(app, "Guest %s does not yet exist, waiting for it to be created\n", - priv->domkey); - goto done; - } else { - virt_viewer_app_simple_message_dialog(app, _("Cannot find guest domain %s"), - priv->domkey); - DEBUG_LOG("Cannot find guest %s", priv->domkey); - goto cleanup; - } - } - - virt_viewer_app_show_status(app, _("Checking guest domain status")); - if (virDomainGetInfo(dom, &info) < 0) { - DEBUG_LOG("Cannot get guest state"); - goto cleanup; - } - - if (info.state == VIR_DOMAIN_SHUTOFF) { - virt_viewer_app_show_status(app, _("Waiting for guest domain to start")); - } else { - ret = virt_viewer_update_display(self, dom); - if (ret >= 0) - ret = VIRT_VIEWER_APP_CLASS(virt_viewer_parent_class)->initial_connect(app); - if (ret < 0) { - if (priv->waitvm) { - virt_viewer_app_show_status(app, _("Waiting for guest domain to start server")); - virt_viewer_app_trace(app, "Guest %s has not activated its display yet, waiting for it to start\n", - priv->domkey); - } else { - DEBUG_LOG("Failed to activate viewer"); - goto cleanup; - } - } else if (ret == 0) { - DEBUG_LOG("Failed to activate viewer"); - ret = -1; - goto cleanup; - } - } + virDomainPtr dom = NULL; + virDomainInfo info; + int ret = -1; + VirtViewer *self = VIRT_VIEWER(app); + VirtViewerPrivate *priv = self->priv; + + virt_viewer_app_show_status(app, _("Finding guest domain")); + dom = virt_viewer_lookup_domain(self); + if (!dom) { + if (priv->waitvm) { + virt_viewer_app_show_status(app, _("Waiting for guest domain to be created")); + virt_viewer_app_trace(app, "Guest %s does not yet exist, waiting for it to be created\n", + priv->domkey); + goto done; + } else { + virt_viewer_app_simple_message_dialog(app, _("Cannot find guest domain %s"), + priv->domkey); + DEBUG_LOG("Cannot find guest %s", priv->domkey); + goto cleanup; + } + } + + virt_viewer_app_show_status(app, _("Checking guest domain status")); + if (virDomainGetInfo(dom, &info) < 0) { + DEBUG_LOG("Cannot get guest state"); + goto cleanup; + } + + if (info.state == VIR_DOMAIN_SHUTOFF) { + virt_viewer_app_show_status(app, _("Waiting for guest domain to start")); + } else { + ret = virt_viewer_update_display(self, dom); + if (ret >= 0) + ret = VIRT_VIEWER_APP_CLASS(virt_viewer_parent_class)->initial_connect(app); + if (ret < 0) { + if (priv->waitvm) { + virt_viewer_app_show_status(app, _("Waiting for guest domain to start server")); + virt_viewer_app_trace(app, "Guest %s has not activated its display yet, waiting for it to start\n", + priv->domkey); + } else { + DEBUG_LOG("Failed to activate viewer"); + goto cleanup; + } + } else if (ret == 0) { + DEBUG_LOG("Failed to activate viewer"); + ret = -1; + goto cleanup; + } + } done: - ret = 0; + ret = 0; cleanup: - if (dom) - virDomainFree(dom); - return ret; + if (dom) + virDomainFree(dom); + return ret; } static void virt_viewer_error_func (void *data G_GNUC_UNUSED, - virErrorPtr error G_GNUC_UNUSED) + virErrorPtr error G_GNUC_UNUSED) { - /* nada */ + /* nada */ } static gboolean virt_viewer_start(VirtViewerApp *app) { - VirtViewer *self = VIRT_VIEWER(app); - VirtViewerPrivate *priv = self->priv; - int cred_types[] = - { VIR_CRED_AUTHNAME, VIR_CRED_PASSPHRASE }; - virConnectAuth auth_libvirt = { - .credtype = cred_types, - .ncredtype = ARRAY_CARDINALITY(cred_types), - .cb = virt_viewer_auth_libvirt_credentials, - .cbdata = (void *)priv->uri, - }; - int oflags = 0; - - if (!virt_viewer_app_get_attach(app)) - oflags |= VIR_CONNECT_RO; - - virt_viewer_events_register(); - - virSetErrorFunc(NULL, virt_viewer_error_func); - - virt_viewer_app_trace(app, "Opening connection to libvirt with URI %s\n", - priv->uri ? priv->uri : "<null>"); - priv->conn = virConnectOpenAuth(priv->uri, - //virConnectAuthPtrDefault, - &auth_libvirt, - oflags); - if (!priv->conn) { - virt_viewer_app_simple_message_dialog(app, _("Unable to connect to libvirt with URI %s"), - priv->uri ? priv->uri : _("[none]")); - return FALSE; - } - - if (virt_viewer_app_initial_connect(app) < 0) - return FALSE; - - if (virConnectDomainEventRegister(priv->conn, - virt_viewer_domain_event, - self, - NULL) < 0) - priv->withEvents = FALSE; - else - priv->withEvents = TRUE; - - if (!priv->withEvents && - !virt_viewer_app_is_active(app)) { - DEBUG_LOG("No domain events, falling back to polling"); - virt_viewer_app_start_reconnect_poll(app); - } - - return VIRT_VIEWER_APP_CLASS(virt_viewer_parent_class)->start(app); + VirtViewer *self = VIRT_VIEWER(app); + VirtViewerPrivate *priv = self->priv; + int cred_types[] = + { VIR_CRED_AUTHNAME, VIR_CRED_PASSPHRASE }; + virConnectAuth auth_libvirt = { + .credtype = cred_types, + .ncredtype = ARRAY_CARDINALITY(cred_types), + .cb = virt_viewer_auth_libvirt_credentials, + .cbdata = (void *)priv->uri, + }; + int oflags = 0; + + if (!virt_viewer_app_get_attach(app)) + oflags |= VIR_CONNECT_RO; + + virt_viewer_events_register(); + + virSetErrorFunc(NULL, virt_viewer_error_func); + + virt_viewer_app_trace(app, "Opening connection to libvirt with URI %s\n", + priv->uri ? priv->uri : "<null>"); + priv->conn = virConnectOpenAuth(priv->uri, + //virConnectAuthPtrDefault, + &auth_libvirt, + oflags); + if (!priv->conn) { + virt_viewer_app_simple_message_dialog(app, _("Unable to connect to libvirt with URI %s"), + priv->uri ? priv->uri : _("[none]")); + return FALSE; + } + + if (virt_viewer_app_initial_connect(app) < 0) + return FALSE; + + if (virConnectDomainEventRegister(priv->conn, + virt_viewer_domain_event, + self, + NULL) < 0) + priv->withEvents = FALSE; + else + priv->withEvents = TRUE; + + if (!priv->withEvents && + !virt_viewer_app_is_active(app)) { + DEBUG_LOG("No domain events, falling back to polling"); + virt_viewer_app_start_reconnect_poll(app); + } + + return VIRT_VIEWER_APP_CLASS(virt_viewer_parent_class)->start(app); } VirtViewer * virt_viewer_new(const char *uri, - const char *name, - gint zoom, - gboolean direct, - gboolean attach, - gboolean waitvm, - gboolean reconnect, - gboolean verbose, - GtkWidget *container) + const char *name, + gint zoom, + gboolean direct, + gboolean attach, + gboolean waitvm, + gboolean reconnect, + gboolean verbose, + GtkWidget *container) { - VirtViewer *self; - VirtViewerApp *app; - VirtViewerPrivate *priv; - - self = g_object_new(VIRT_VIEWER_TYPE, - "container", container, - "verbose", verbose, - "guest-name", name, - NULL); - app = VIRT_VIEWER_APP(self); - priv = self->priv; - - /* Set initial title based on guest name arg, which can be a ID, - * UUID, or NAME string. To be replaced with the real guest name later - */ - g_object_set(app, "title", name, NULL); - virt_viewer_window_set_zoom_level(virt_viewer_app_get_main_window(app), zoom); - virt_viewer_app_set_direct(app, direct); - virt_viewer_app_set_attach(app, attach); - - /* should probably be properties instead */ - priv->uri = g_strdup(uri); - priv->domkey = g_strdup(name); - priv->waitvm = waitvm; - priv->reconnect = reconnect; - - return self; + VirtViewer *self; + VirtViewerApp *app; + VirtViewerPrivate *priv; + + self = g_object_new(VIRT_VIEWER_TYPE, + "container", container, + "verbose", verbose, + "guest-name", name, + NULL); + app = VIRT_VIEWER_APP(self); + priv = self->priv; + + /* Set initial title based on guest name arg, which can be a ID, + * UUID, or NAME string. To be replaced with the real guest name later + */ + g_object_set(app, "title", name, NULL); + virt_viewer_window_set_zoom_level(virt_viewer_app_get_main_window(app), zoom); + virt_viewer_app_set_direct(app, direct); + virt_viewer_app_set_attach(app, attach); + + /* should probably be properties instead */ + priv->uri = g_strdup(uri); + priv->domkey = g_strdup(name); + priv->waitvm = waitvm; + priv->reconnect = reconnect; + + return self; } /* * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 - * indent-tabs-mode: t + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil * End: */ diff --git a/src/virt-viewer.h b/src/virt-viewer.h index 02512ca..d36d7d6 100644 --- a/src/virt-viewer.h +++ b/src/virt-viewer.h @@ -38,27 +38,35 @@ G_BEGIN_DECLS typedef struct _VirtViewerPrivate VirtViewerPrivate; typedef struct { - VirtViewerApp parent; - VirtViewerPrivate *priv; + VirtViewerApp parent; + VirtViewerPrivate *priv; } VirtViewer; typedef struct { - VirtViewerAppClass parent_class; + VirtViewerAppClass parent_class; } VirtViewerClass; GType virt_viewer_get_type (void); VirtViewer * virt_viewer_new(const char *uri, - const char *name, - gint zoom, - gboolean direct, - gboolean attach, - gboolean waitvm, - gboolean reconnect, - gboolean verbose, - GtkWidget *container); + const char *name, + gint zoom, + gboolean direct, + gboolean attach, + gboolean waitvm, + gboolean reconnect, + gboolean verbose, + GtkWidget *container); G_END_DECLS #endif /* VIRT_VIEWER_H */ + +/* + * Local variables: + * c-indent-level: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ |