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 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
#define DEFAULT_INI_FILE_NAME "llcon.ini"
#define DEFAULT_INI_FILE_NAME_SERVER "llconserver.ini"

View file

@ -27,6 +27,7 @@
/* Implementation *************************************************************/
CLlconServerDlg::CLlconServerDlg ( CServer* pNServP,
const bool bStartMinimized,
QWidget* parent,
Qt::WindowFlags f )
: QDialog ( parent, f ),
@ -37,18 +38,6 @@ CLlconServerDlg::CLlconServerDlg ( CServer* pNServP,
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 -----------------------------------------------
// 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" ) );
// TODO does not work!
// act on "start minimized" flag
if ( bStartMinimized )
{
hide();
}
// check if system tray icon can be used
bSystemTrayIconAvaialbe = SystemTrayIcon.isSystemTrayAvailable();
@ -218,6 +217,26 @@ ListViewClients->setMinimumHeight ( 140 );
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
UpdateGUIDependencies();
@ -247,6 +266,9 @@ ListViewClients->setMinimumHeight ( 140 );
QObject::connect ( cbDefaultCentralServer, SIGNAL ( stateChanged ( int ) ),
this, SLOT ( OnDefaultCentralServerStateChanged ( int ) ) );
QObject::connect ( cbStartOnOSStart, SIGNAL ( stateChanged ( int ) ),
this, SLOT ( OnStartOnOSStartStateChanged ( int ) ) );
// line edits
QObject::connect ( LineEditCentralServerAddress,
SIGNAL ( editingFinished() ),
@ -282,6 +304,15 @@ ListViewClients->setMinimumHeight ( 140 );
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 )
{
// 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 )
{
// 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:
CLlconServerDlg ( CServer* pNServP,
const bool bStartMinimized,
QWidget* parent = 0,
Qt::WindowFlags f = 0 );
@ -68,6 +69,7 @@ protected:
void UpdateGUIDependencies();
void UpdateSystemTrayIcon ( const bool bIsActive );
void ShowWindowInForeground() { showNormal(); raise(); }
void ModifyAutoStartEntry ( const bool bDoAutoStart );
QTimer Timer;
CServer* pServer;
@ -86,6 +88,7 @@ protected:
public slots:
void OnRegisterServerStateChanged ( int value );
void OnDefaultCentralServerStateChanged ( int value );
void OnStartOnOSStartStateChanged ( int value );
void OnLineEditCentralServerAddressEditingFinished();
void OnLineEditServerNameTextChanged ( const QString& strNewName );
void OnLineEditLocationCityTextChanged ( const QString& strNewCity );

View file

@ -6,7 +6,7 @@
<x>0</x>
<y>0</y>
<width>588</width>
<height>378</height>
<height>386</height>
</rect>
</property>
<property name="windowTitle" >
@ -51,10 +51,17 @@
</column>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbStartOnOSStart" >
<property name="text" >
<string>Start Minimized on Windows Start</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbRegisterServer" >
<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>
</widget>
</item>

View file

@ -55,6 +55,7 @@ int main ( int argc, char** argv )
// arguments
bool bIsClient = true;
bool bUseGUI = true;
bool bStartMinimized = false;
bool bConnectOnStartup = false;
bool bDisalbeLEDs = false;
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 ---------------------------------------------------
if ( GetFlagArgument ( argv,
i,
@ -361,6 +374,7 @@ int main ( int argc, char** argv )
// GUI object for the server
CLlconServerDlg ServerDlg (
&Server,
bStartMinimized,
0,
Qt::Window );
@ -419,6 +433,7 @@ QString UsageArguments ( char **argv )
"\nRecognized options:\n"
" -s, --server start server\n"
" -n, --nogui disable GUI (server only)\n"
" -z, --startminimized start minimizied (server only)\n"
" -l, --log enable logging, set file name\n"
" -i, --inifile initialization file name (client only)\n"
" -p, --port local port number (server only)\n"

View file

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

View file

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

View file

@ -231,6 +231,12 @@ void CSettings::ReadIniFile ( const QString& sFileName )
{
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
SetNumericIniSet ( IniXMLDocument, "server", "country",
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