summaryrefslogtreecommitdiffstats
path: root/kxmleditor/main.cpp
blob: 7c7726fb3ca7a5fdad6c5ce2f7ce5ab34d8592e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/***************************************************************************
                          main.cpp  -  description
                             -------------------
    begin                : � �c 10 12:39:26 CEST 2001
    copyright            : (C) 2001, 2002, 2003 by The KXMLEditor Team
    email                : lvanek@users.sourceforge.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <tdeapplication.h>
#include <tdecmdlineargs.h>
#include <tdeaboutdata.h>
#include <tdelocale.h>
#include <kdebug.h>
#include <tdemessagebox.h>
#include <dcopclient.h>

//#include "kxmleditor.h"
#include "../part/kxmleditorabout.h"
#include "kxmleditorshell.h"


static TDECmdLineOptions options[] =
{
  { "+[File(s)]", I18N_NOOP("XML file(s) to open"), 0 },
  { 0, 0, 0 }
};

#define USE_KPART 1
	// if set to true makes kxmleditor to be kpart based (currently developement version only)

/** @short Main application function that starts-up the application */
int main(int argc, char *argv[])
{
	TDECmdLineArgs::init( argc, argv, new KXMLEditorAboutData() );
	TDECmdLineArgs::addCmdLineOptions( options ); // Add our own options.

	TDEApplication app;

  // comment the following lines to use KXMLEditorShell instead of KXMLEditorApp
#if ! USE_KPART
  if (app.isRestored())
  	{ RESTORE(KXMLEditorApp);
  	}
  else
  {
    KXMLEditorApp *kxmleditor = new KXMLEditorApp();
    kxmleditor->show();

    TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();

		if(args->count())
			{ TQString strPath;

			  if(args->count() > 1)
					{ strPath = args->arg(1);
					}
          KURL url(args->arg(0));
					if ( ! url.isValid() )
						{ // probably user entered just filename
							url.setProtocol("file");
							url.setPath(args->arg(0));
						}
					kxmleditor->openDocumentFile(url, strPath);
			}
		else
			{ kxmleditor->openDocumentFile();
			}
		args->clear();
  }
#else // USE_KPART

	if (app.isRestored())
	{
		RESTORE(KXMLEditorShell);
	}
	else
	{
		TDECmdLineArgs * pArgs = TDECmdLineArgs::parsedArgs();
		KXMLEditorShell * pShell;
		bool bNoCorrectInstance = true;
		if ( pArgs->count() > 0 )
		{
			for( int i = 0; i < pArgs->count(); i++ )
			{
				KURL url(pArgs->arg(i));
				if ( ! url.isValid() )
				{
					url.setProtocol("file");
					url.setPath(pArgs->arg(i));
				}
				pShell = new KXMLEditorShell();
				if ( pShell->openURL(url) )
				{
					pShell->show();
					bNoCorrectInstance = false;
				}
				else
					{
            kdDebug() << "Couldn't open file " << url.path() << endl;
            KMessageBox::sorry(0, i18n("Couldn't open file !") + "\n" + url.path());
            delete pShell;
          }
			}
		}
		else
		{
			pShell = new KXMLEditorShell();
			KParts::ReadWritePart* pPart = KXMLEditorShell::createXMLPart(pShell);
			pShell->setPart(pPart);
			pShell->show();
			bNoCorrectInstance = false;
		}
		pArgs->clear();

		if ( bNoCorrectInstance )
			return FALSE;
	}

	// registration as multi-instance DCOP client
	DCOPClient *client = app.dcopClient();
	client->attach();
	client->registerAs(kapp->name());

  // uncomment end
#endif // USE_KPART

  int iRetVal = app.exec();
  return iRetVal;
}