summaryrefslogtreecommitdiffstats
path: root/tools/kthesaurus/main.cc
blob: a7e74822946131cfc621a27da84d2bbe168a9259 (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
/***************************************************************************
                       main.cc - using the thesaurus KDataTool stand alone
                       -------------------
    begin            : 2001-12-22
    copyright        : (C) 2001 by Daniel Naber
    email            : daniel.naber@t-online.de
	$Id: main.cc 381440 2005-01-23 07:53:34Z mlaurent $
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 <tqstring.h>

#include <kaboutdata.h>
#include <kapplication.h>
#include <kcmdlineargs.h>
#include <kdatatool.h>
#include <kdebug.h>
#include <kglobal.h>
#include <klocale.h>
#include <koffice_export.h>
static KCmdLineOptions options[] =
{
	{ "+[term]",   I18N_NOOP("Term to search for when starting up"), 0 },
	KCmdLineLastOption
};

extern "C" KOFFICETOOLS_EXPORT int kdemain(int argc, char **argv)
{

	KAboutData aboutData("kthesaurus", I18N_NOOP("KThesaurus"), "1.0",
		I18N_NOOP( "KThesaurus - List synonyms" ), KAboutData::License_GPL,
		I18N_NOOP( "(c) 2001 Daniel Naber" ) );

	KCmdLineArgs::init(argc, argv, &aboutData);
	KCmdLineArgs::addCmdLineOptions(options);
	KApplication a; // KDataTool needs an instance

	// TODO: take term from command line!

	KService::Ptr service = KService::serviceByDesktopName("thesaurustool");
	if( ! service ) {
		kdWarning() << "Could not find Service/KDataTool 'thesaurustool'!" << endl;
		return 1;
	}

	KDataToolInfo *info = new KDataToolInfo(service, 0);
	KDataTool *tool = info->createTool();
	if ( !tool ) {
		kdWarning() << "Could not create tool 'thesaurustool'!" << endl;
		return 2;
	}

/* TODO: get selection(), not only clipboard!
	TQClipboard *cb = TQApplication::tqclipboard();
	TQString text = cb->text();
	if( text.isNull() || text.length() > 50 ) {
		// long texts are probably not supposed to be searched for
		text = "";
	}
*/
	TQString text = "";
	KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
	if ( args->count() > 0 ) {
		text = args->arg(0);
	}

	TQString command = "thesaurus_standalone";	// 'standalone' will give us different buttons
	TQString mimetype = "text/plain";
	TQString datatype = TQSTRING_OBJECT_NAME_STRING;

	//kdDebug() << "KThesaurus command=" << command
	//		<< " dataType=" << info->dataType() << endl;

	tool->run(command, &text, datatype, mimetype);

	delete tool;

	return 0;
}