summaryrefslogtreecommitdiffstats
path: root/plugins/applications/kbfxplasmadataplugin.cpp
blob: 43312ffca0a9b977129312b261b89fd12f149a50 (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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
 *   Copyright (C) 2006
 *   Siraj Razick <siraj@kdemail.net>
 *   PhobosK <phobosk@mail.kbfx.org>
 *   see Also AUTHORS
 *
 *   This program 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 program 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 General Public License for more details
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include <dcopref.h>
#include <kapplication.h>
#include <kdebug.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <krun.h>
#include <kservice.h>
#include <kservicegroup.h>

#include <kbfxconfig.h>

#include <kbfxplasmadataplugin-common.h>


void
browseApp ( KServiceGroup::Ptr service, KbfxDataGroupList * glist,
            KbfxDataGroup * appGroup )
{
	if ( !service || !service->isValid () )
		return;


	KServiceGroup::List list = service->entries ( true, true, false, true );


	if ( service->noDisplay () == true )
		return;

	/*
	  if (list.count () <= 0)
	    return;
	*/

	appGroup = new KbfxDataGroup ();
	appGroup->setName ( service->caption () );

	for ( KServiceGroup::List::ConstIterator it = list.begin ();
	        it != list.end (); it++ )
	{
		KSycocaEntry *p = ( *it );
		if ( p->isType ( KST_KService ) )
		{
			KService *s = static_cast < KService * > ( p );
			KbfxDataSource *data = new KbfxDataSource ();
			data->setDesktopPath ( s->desktopEntryPath () );
			appGroup->addItem ( data );
		}
		else if ( p->isType ( KST_KServiceGroup ) )
		{
			KServiceGroup *g = static_cast < KServiceGroup * > ( p );
			if ( g->childCount () > 0 )
			{
				glist->addGroup ( appGroup );
				appGroup = new KbfxDataGroup ();
				appGroup->setName ( g->caption () );
				browseApp ( g, glist, appGroup );
			}

		}
	}
	glist->addGroup ( appGroup );

}






KbfxDataStack *
view ()
{
	KbfxDataGroup *appGroup = new KbfxDataGroup ();
	KbfxDataGroupList *glist = new KbfxDataGroupList ();
	KbfxDataStack *gstack = new KbfxDataStack ();

	KServiceGroup::Ptr service = KServiceGroup::group ( "/" );
	if ( service == NULL)
	{
		int messageBoxUserResReturn = KMessageBox::questionYesNo ( 0,
				tr2i18n ( "<p align='center'>There is a problem in TDE Menu services!<br>KBFX can try to autorepair this problem.<br>Should KBFX autorepair this problem?</p>" ),
				tr2i18n ( "Problem in TDE Menu Services" ),
				tr2i18n ( "Do Autorepair" ),
				tr2i18n ( "Do NOT Autorepair" ) );
		if ( messageBoxUserResReturn == KMessageBox::Yes )
		{
			KRun::runCommand ( "tdebuildsycoca" );
//			if ( ! ConfigInit().m_KbfxWatcher )
//			{
				DCOPRef m_kickerPanel("kicker", "kicker");
				m_kickerPanel.call("restart()");
//			}
		}
                return new KbfxDataStack();
	}

	service->setShowEmptyMenu ( false );

	glist->setName ( "Applications" );
	appGroup->setName ( service->caption () );

	KServiceGroup::List list = service->entries ( true, true, false, false );

	if ( list.count() <= 0)
	{
        	return new KbfxDataStack();
	}


	for ( KServiceGroup::List::ConstIterator it = list.begin ();
	        it != list.end (); it++ )
	{
		KSycocaEntry *p = ( *it );
		if ( p->isType ( KST_KService ) )
		{}
		else if ( p->isType ( KST_KServiceGroup ) )
		{
			KServiceGroup *g = static_cast < KServiceGroup * > ( p );
			g->setShowEmptyMenu ( false );

			if ( g->childCount () > 0 )
			{
				glist = new KbfxDataGroupList ();
				glist->setName ( g->caption () );
				glist->setIcon ( g->icon () );
				browseApp ( g, glist, appGroup );
				gstack->addGroupList ( glist );
			}

		}
	}

	gstack->setName ( "Applications" );


	return gstack;

}

TQString
name ()
{
	return TQString ( "Applications" );
}

TQString
type ()
{
	return TQString ( "Stub Type" );
}


uint
id ()
{
	return 1;			//TODO see what can be done... manybe rand()?
}

#include <ktrader.h>

KbfxDataGroup *
search ( TQString _keyword )
{


	KbfxDataGroup *g = new KbfxDataGroup ();
	g->setName ( "Applications" );


	KTrader::OfferList offers = KTrader::self ()->query ( "Application" );

	int *count = new int;
	*count = 0;
	TQValueListIterator < KService::Ptr > s = offers.begin ();

	for ( ; s != offers.end (); ++s )
	{
		if ( s == NULL )
			continue;
		if ( (*s)->noDisplay () == true )
			continue;

		TQString *sPtr = new TQString ();

		( *sPtr ) = ( *s )->name () + ( *s )->genericName () + ( *s )->comment ();
		if ( ( !sPtr->isNull () ) && sPtr->contains ( _keyword, false ) > 0 )
		{
			KbfxDataSource *data = new KbfxDataSource ();
			data->setName ( ( *s )->name () );
			data->setDesktopPath ( ( *s )->desktopEntryPath () );

			g->addItem ( data );
			( *count ) ++;
			if ( ( *count ) == 10 )
				break;

		}
		if ( sPtr != 0 )
			delete sPtr;
	}
	delete count;
	return g;
}