support for auto start minimized on Windows (not yet finished)

This commit is contained in:
Volker Fischer 2011-05-08 15:01:20 +00:00
parent 8e92d26b70
commit 73dc8e1d77
8 changed files with 136 additions and 15 deletions

View file

@ -46,6 +46,9 @@
#define VERSION "4.0.0cvs" #define VERSION "4.0.0cvs"
#define APP_NAME "llcon" #define APP_NAME "llcon"
// Windows registry key name of auto run entry for the server
#define AUTORUN_SERVER_REG_NAME "llcon server"
// default names of the ini-file for client and server // default names of the ini-file for client and server
#define DEFAULT_INI_FILE_NAME "llcon.ini" #define DEFAULT_INI_FILE_NAME "llcon.ini"
#define DEFAULT_INI_FILE_NAME_SERVER "llconserver.ini" #define DEFAULT_INI_FILE_NAME_SERVER "llconserver.ini"

View file

@ -27,6 +27,7 @@
/* Implementation *************************************************************/ /* Implementation *************************************************************/
CLlconServerDlg::CLlconServerDlg ( CServer* pNServP, CLlconServerDlg::CLlconServerDlg ( CServer* pNServP,
const bool bStartMinimized,
QWidget* parent, QWidget* parent,
Qt::WindowFlags f ) Qt::WindowFlags f )
: QDialog ( parent, f ), : QDialog ( parent, f ),
@ -37,18 +38,6 @@ CLlconServerDlg::CLlconServerDlg ( CServer* pNServP,
setupUi ( this ); setupUi ( this );
// TEST
#ifdef _WIN32
/*
QSettings RegSettings ( "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
QSettings::NativeFormat );
RegSettings.setValue ( "llcon server",
QCoreApplication::applicationFilePath().replace ( "/", "\\" ) );
*/
#endif
// Add help text to controls ----------------------------------------------- // Add help text to controls -----------------------------------------------
// client list // client list
ListViewClients->setWhatsThis ( tr ( "<b>Client List:</b> The client list " ListViewClients->setWhatsThis ( tr ( "<b>Client List:</b> The client list "
@ -117,6 +106,16 @@ RegSettings.setValue ( "llcon server",
"Country where the server is located combo box" ) ); "Country where the server is located combo box" ) );
// TODO does not work!
// act on "start minimized" flag
if ( bStartMinimized )
{
hide();
}
// check if system tray icon can be used // check if system tray icon can be used
bSystemTrayIconAvaialbe = SystemTrayIcon.isSystemTrayAvailable(); bSystemTrayIconAvaialbe = SystemTrayIcon.isSystemTrayAvailable();
@ -218,6 +217,26 @@ ListViewClients->setMinimumHeight ( 140 );
cbRegisterServer->setCheckState ( Qt::Unchecked ); cbRegisterServer->setCheckState ( Qt::Unchecked );
} }
// update start minimized check box (only available for Windows)
#ifndef _WIN32
cbStartOnOSStart->setVisible ( false );
#else
const bool bCurAutoStartMinState = pServer->GetAutoRunMinimized();
if ( bCurAutoStartMinState )
{
cbStartOnOSStart->setCheckState ( Qt::Checked );
}
else
{
cbStartOnOSStart->setCheckState ( Qt::Unchecked );
}
// modify registry according to setting (this is just required in case a
// user has changed the registry by hand)
ModifyAutoStartEntry ( bCurAutoStartMinState );
#endif
// update GUI dependencies // update GUI dependencies
UpdateGUIDependencies(); UpdateGUIDependencies();
@ -247,6 +266,9 @@ ListViewClients->setMinimumHeight ( 140 );
QObject::connect ( cbDefaultCentralServer, SIGNAL ( stateChanged ( int ) ), QObject::connect ( cbDefaultCentralServer, SIGNAL ( stateChanged ( int ) ),
this, SLOT ( OnDefaultCentralServerStateChanged ( int ) ) ); this, SLOT ( OnDefaultCentralServerStateChanged ( int ) ) );
QObject::connect ( cbStartOnOSStart, SIGNAL ( stateChanged ( int ) ),
this, SLOT ( OnStartOnOSStartStateChanged ( int ) ) );
// line edits // line edits
QObject::connect ( LineEditCentralServerAddress, QObject::connect ( LineEditCentralServerAddress,
SIGNAL ( editingFinished() ), SIGNAL ( editingFinished() ),
@ -282,6 +304,15 @@ ListViewClients->setMinimumHeight ( 140 );
Timer.start ( GUI_CONTRL_UPDATE_TIME ); Timer.start ( GUI_CONTRL_UPDATE_TIME );
} }
void CLlconServerDlg::OnStartOnOSStartStateChanged ( int value )
{
const bool bCurAutoStartMinState = ( value == Qt::Checked );
// update registry and server setting (for ini file)
pServer->SetAutoRunMinimized ( bCurAutoStartMinState );
ModifyAutoStartEntry ( bCurAutoStartMinState );
}
void CLlconServerDlg::OnDefaultCentralServerStateChanged ( int value ) void CLlconServerDlg::OnDefaultCentralServerStateChanged ( int value )
{ {
// apply new setting to the server and update it // apply new setting to the server and update it
@ -471,6 +502,47 @@ void CLlconServerDlg::UpdateSystemTrayIcon ( const bool bIsActive )
} }
} }
void CLlconServerDlg::ModifyAutoStartEntry ( const bool bDoAutoStart )
{
// auto start is currently only supported for Windows
#ifdef _WIN32
// init settings object so that it points to the correct place in the
// Windows registry for the auto run entry
QSettings RegSettings ( "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
QSettings::NativeFormat );
// create start string of auto run entry
QString strRegValue =
QCoreApplication::applicationFilePath().replace ( "/", "\\" ) +
" --startminimized";
#endif
if ( bDoAutoStart )
{
#ifdef _WIN32
// ckeck if registry entry is correctly present, if not, correct
const bool bWriteRegValue = strRegValue.compare (
RegSettings.value ( AUTORUN_SERVER_REG_NAME ).toString() );
if ( bWriteRegValue )
{
// write reg key in the registry
RegSettings.setValue ( AUTORUN_SERVER_REG_NAME, strRegValue );
}
#endif
}
else
{
#ifdef _WIN32
// delete reg key if present
if ( RegSettings.contains ( AUTORUN_SERVER_REG_NAME ) )
{
RegSettings.remove ( AUTORUN_SERVER_REG_NAME );
}
#endif
}
}
void CLlconServerDlg::changeEvent ( QEvent* pEvent ) void CLlconServerDlg::changeEvent ( QEvent* pEvent )
{ {
// if we have a system tray icon, we make the window invisible if it is // if we have a system tray icon, we make the window invisible if it is

View file

@ -58,6 +58,7 @@ class CLlconServerDlg : public QDialog, private Ui_CLlconServerDlgBase
public: public:
CLlconServerDlg ( CServer* pNServP, CLlconServerDlg ( CServer* pNServP,
const bool bStartMinimized,
QWidget* parent = 0, QWidget* parent = 0,
Qt::WindowFlags f = 0 ); Qt::WindowFlags f = 0 );
@ -68,6 +69,7 @@ protected:
void UpdateGUIDependencies(); void UpdateGUIDependencies();
void UpdateSystemTrayIcon ( const bool bIsActive ); void UpdateSystemTrayIcon ( const bool bIsActive );
void ShowWindowInForeground() { showNormal(); raise(); } void ShowWindowInForeground() { showNormal(); raise(); }
void ModifyAutoStartEntry ( const bool bDoAutoStart );
QTimer Timer; QTimer Timer;
CServer* pServer; CServer* pServer;
@ -86,6 +88,7 @@ protected:
public slots: public slots:
void OnRegisterServerStateChanged ( int value ); void OnRegisterServerStateChanged ( int value );
void OnDefaultCentralServerStateChanged ( int value ); void OnDefaultCentralServerStateChanged ( int value );
void OnStartOnOSStartStateChanged ( int value );
void OnLineEditCentralServerAddressEditingFinished(); void OnLineEditCentralServerAddressEditingFinished();
void OnLineEditServerNameTextChanged ( const QString& strNewName ); void OnLineEditServerNameTextChanged ( const QString& strNewName );
void OnLineEditLocationCityTextChanged ( const QString& strNewCity ); void OnLineEditLocationCityTextChanged ( const QString& strNewCity );

View file

@ -6,7 +6,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>588</width> <width>588</width>
<height>378</height> <height>386</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle" >
@ -51,10 +51,17 @@
</column> </column>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="cbStartOnOSStart" >
<property name="text" >
<string>Start Minimized on Windows Start</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QCheckBox" name="cbRegisterServer" > <widget class="QCheckBox" name="cbRegisterServer" >
<property name="text" > <property name="text" >
<string>Register My Server at Central Server</string> <string>Register My Server in the Server List at the Central Server</string>
</property> </property>
</widget> </widget>
</item> </item>

View file

@ -55,6 +55,7 @@ int main ( int argc, char** argv )
// arguments // arguments
bool bIsClient = true; bool bIsClient = true;
bool bUseGUI = true; bool bUseGUI = true;
bool bStartMinimized = false;
bool bConnectOnStartup = false; bool bConnectOnStartup = false;
bool bDisalbeLEDs = false; bool bDisalbeLEDs = false;
quint16 iPortNumber = LLCON_DEFAULT_PORT_NUMBER; quint16 iPortNumber = LLCON_DEFAULT_PORT_NUMBER;
@ -95,6 +96,18 @@ int main ( int argc, char** argv )
} }
// Start minimized -----------------------------------------------------
if ( GetFlagArgument ( argv,
i,
"-z",
"--startminimized" ) )
{
bStartMinimized = true;
tsConsole << "- start minimized enabled" << endl;
continue;
}
// Disable LEDs flag --------------------------------------------------- // Disable LEDs flag ---------------------------------------------------
if ( GetFlagArgument ( argv, if ( GetFlagArgument ( argv,
i, i,
@ -361,6 +374,7 @@ int main ( int argc, char** argv )
// GUI object for the server // GUI object for the server
CLlconServerDlg ServerDlg ( CLlconServerDlg ServerDlg (
&Server, &Server,
bStartMinimized,
0, 0,
Qt::Window ); Qt::Window );
@ -419,6 +433,7 @@ QString UsageArguments ( char **argv )
"\nRecognized options:\n" "\nRecognized options:\n"
" -s, --server start server\n" " -s, --server start server\n"
" -n, --nogui disable GUI (server only)\n" " -n, --nogui disable GUI (server only)\n"
" -z, --startminimized start minimizied (server only)\n"
" -l, --log enable logging, set file name\n" " -l, --log enable logging, set file name\n"
" -i, --inifile initialization file name (client only)\n" " -i, --inifile initialization file name (client only)\n"
" -p, --port local port number (server only)\n" " -p, --port local port number (server only)\n"

View file

@ -176,7 +176,8 @@ CServer::CServer ( const QString& strLoggingFileName,
ServerListManager ( iPortNumber, ServerListManager ( iPortNumber,
strCentralServer, strCentralServer,
strServerInfo, strServerInfo,
&ConnLessProtocol ) &ConnLessProtocol ),
bAutoRunMinimized ( false )
{ {
int i; int i;

View file

@ -165,6 +165,13 @@ public:
QLocale::Country GetServerCountry() QLocale::Country GetServerCountry()
{ return ServerListManager.GetServerCountry(); } { return ServerListManager.GetServerCountry(); }
// GUI settings ------------------------------------------------------------
void SetAutoRunMinimized ( const bool NAuRuMin )
{ bAutoRunMinimized = NAuRuMin; }
bool GetAutoRunMinimized() { return bAutoRunMinimized; }
protected: protected:
// access functions for actual channels // access functions for actual channels
bool IsConnected ( const int iChanNum ) bool IsConnected ( const int iChanNum )
@ -224,6 +231,9 @@ protected:
// server list // server list
CServerListManager ServerListManager; CServerListManager ServerListManager;
// GUI settings
bool bAutoRunMinimized;
signals: signals:
void Started(); void Started();
void Stopped(); void Stopped();

View file

@ -231,6 +231,12 @@ void CSettings::ReadIniFile ( const QString& sFileName )
{ {
pServer->SetServerCountry ( static_cast<QLocale::Country> ( iValue ) ); pServer->SetServerCountry ( static_cast<QLocale::Country> ( iValue ) );
} }
// start minimized on OS start
if ( GetFlagIniSet ( IniXMLDocument, "server", "autostartmin", bValue ) )
{
pServer->SetAutoRunMinimized ( bValue );
}
} }
} }
@ -352,6 +358,10 @@ void CSettings::WriteIniFile ( const QString& sFileName )
// country // country
SetNumericIniSet ( IniXMLDocument, "server", "country", SetNumericIniSet ( IniXMLDocument, "server", "country",
static_cast<int> ( pServer->GetServerCountry() ) ); static_cast<int> ( pServer->GetServerCountry() ) );
// start minimized on OS start
SetFlagIniSet ( IniXMLDocument, "server", "autostartmin",
pServer->GetAutoRunMinimized() );
} }
// prepare file name for storing initialization data in XML file and store // prepare file name for storing initialization data in XML file and store