[Kde-windows] KDE/kdelibs/win

Ralf Habacker ralf.habacker at freenet.de
Mon Oct 17 19:41:41 CEST 2005


Am Montag, 17. Oktober 2005 18:34 schrieb Jarosław Staniek:
> Ralf Habacker said the following, On 2005-10-17 18:06:
> > Am Montag, 17. Oktober 2005 16:59 schrieb Jarosław Staniek:
> >>Ralf Habacker said the following, On 2005-10-17 16:47:
> >>>SVN commit 471384 by habacker:
> >>>
> >>>don't need this stuff for qt4, dcopserver runs without it
> >>>
> >>> D             bootstrap.cpp
> >>
> >>Hm?
> >>bootstrap.cpp is not only for qeventloop. Look at the code and docs...
> >>More code like this will go here too. Or have you moved this somewhere?
> >
> > You mean this bootstrap stuff which is called  before main and requires
> > special hacking of the main function ?
> >
> > The eventloop startup is obsolate , but I have overseen that there will
> > be directories created and the HOME var set in win95 case, sorry. I have
> > readded this file without the qeventloop stuff.
> >
> > BTW: Should KDE really  support win95 ?
>
> KDE? I never worked on KDE for windows but on kdelibs.
> Read explanation here, again (hmm, offline currently):
> http://wiki.kde.org/tiki-index.php?page=KDElibs+for+win32
>
> > And what about the network startup
> > stuff ? KICE calls it too and QT as far as I can see too ?
>
> which one 'network startup'?
>

KDEWIN32_EXPORT void kde_bootstrap()
{
	...
	WSADATA wsadata;
	WSAStartup(MAKEWORD(2,2),&wsadata);

This function starts up networking.

See 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/wsastartup_2.asp

> > BTW2: I think that there is a better way to create pre/after main
> > functions. You can create a class and create a global instance of this.
> > This instance will be created and the constructor be called before main.
> >
> >
> > #include <stdio.h>
> >
> > class KDEbootstrap {
> > public:
> > 	KDEbootstrap();
> > 	~KDEbootstrap();
> > };
> >
> >
> > KDEbootstrap::KDEbootstrap()
> > {
> > 	printf("bootstrap created\n");
> > 	// stuff called before main
> > }
> >
> > KDEbootstrap::~KDEbootstrap()
> > {
> > 	printf("bootstrap delete\n");
> > 	// stuff called after main
> > }
> >
> > KDEbootstrap bootstrap;
>
> We dont want to require devs to put
>
> KDEbootstrap bootstrap;
>
> into application code (e.g. main.cpp).
>
>
> So where do you want to put it? My candidate could be KInstance....

See the updated bootsrap.cpp (kde_bootstrap() may be directly included into 
the constructor and kde_destroy() in the destructor)

/*
   This file is part of the KDE libraries
   Copyright (C) 2004 Jaroslaw Staniek <js at iidea.pl>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include <windows.h>
#include <string.h>
#include <stdlib.h>
#include <io.h>
#include <sys/file.h>
#include <stdio.h>

/**
 Actions to perform at very early stage of KDE application life on MS Windows.
 Currently not much is performed here but later, who knows...

 Additional algorithm for win9x (including Millenium), where are problems with 
 easy setting environment variables:

 - try to find HOME env. variable
 - if not found, try to find USERPROFILE env. variable
 - if not found, try to find both HOMEDRIVE and HOMEPATH env. variables
 - if not found, try in the Windows Registry:
   - try get 'Software\KDE' value from HKEY_CURRENT_USER section of Windows 
Registry
   - if not found, try to get from 
     'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell 
Folders\AppData'
   - if one of above two found, put the value as HOME environment variable 
     using putenv() function.

 Once HOME variable is set, Qt handles it well.
*/
void kde_bootstrap()
{
	OSVERSIONINFOA osver;
	osver.dwOSVersionInfoSize = sizeof(osver);
	DWORD rc = GetVersionExA( &osver );

	// TODO: If an application uses the kICE library or QSocketLayer and 
derivated,  
	//       WSAStartup will be done more then once. Don't know if this will be a 
problem 
	WSADATA wsadata;
	WSAStartup(MAKEWORD(2,2),&wsadata);

	//for win9x only:
	if (osver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
		//set $HOME if not available
		char *s, *s2;
		s = getenv("HOME");
		if (!s)
			s = getenv("USERPROFILE");
		if (!s) {
			s = getenv("HOMEDRIVE");
			s2 = getenv("HOMEPATH");
			if (!s2)
				s = 0;
		}
		if (!s) {
			//no $HOME! : set a value from registry:
			HKEY hKey;
			DWORD  len;
			char path[1024];
			char path2[1024];
			bool ok;
#define KEY "Software\\KDE"
			ok = (ERROR_SUCCESS == RegOpenKeyExA( HKEY_CURRENT_USER, KEY, 0, 
KEY_QUERY_VALUE, &hKey ));
			if (ok) {
				len = sizeof(path);
				ok = (ERROR_SUCCESS == RegQueryValueExA( hKey, "HOME", 0, 0, (LPBYTE)path, 
&len ));
				fprintf(stderr,"RegQueryValueExA = %d, %s\n", ok, path);
			}
#define KEY2 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell 
Folders"
			if (!ok) {
				ok = (ERROR_SUCCESS == RegOpenKeyExA( HKEY_CURRENT_USER, KEY, 0, 
KEY_QUERY_VALUE, &hKey ));
				if (ok) {
					len = sizeof(path);
					ok = (ERROR_SUCCESS == RegQueryValueExA( hKey, "AppData", 0, 0, 
(LPBYTE)path, &len ));
					fprintf(stderr,"RegQueryValueExA = %d, %s\n", ok, path);
				}
			}
			if (ok) {
				ok = (0==access(path, R_OK));
				if (!ok) {
					CreateDirectoryA(path,NULL);
					ok = (0==access(path, R_OK));
					fprintf(stderr,"CreateDirectoryA(%s) = %d\n", path, ok);
				}

				if (ok) {
					//it's not a problem with encoding, because Qt will use fromLocal8Bit()
					strcpy(path2, "HOME=");
					strncat(path2, path, sizeof(path2)-1-strlen(path2));
					rc = putenv(path2);
					fprintf(stderr,"putenv(HOME) = %d\n",(int)rc);
/*
					path[0]=0;
					char *p = getenv( "HOME" );
					fprintf(stderr,"getenv(HOME) = %s\n", p);*/
				}
				else
					fprintf(stderr,"'%s' doesn't exist\n",path);
			}
			else
				fprintf(stderr,"$HOME not found!\n",path);

			RegCloseKey( hKey );
		}
	}
}

/**
 Actions to perform after destroying KDE application on MS Windows.
*/
void kde_destroy()
{
}

class KDEbootstrap {
public:
	KDEbootstrap();
	~KDEbootstrap();
};


KDEbootstrap::KDEbootstrap()
{
	// stuff called before main
	kde_bootstrap();
}

KDEbootstrap::~KDEbootstrap()
{
	// stuff called after main
	kde_destroy();
}

KDEbootstrap bootstrap;



Regards 
Ralf 



More information about the Kde-windows mailing list