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
|
/***************************************************************************
* Copyright (C) 2006 by Jens Dagerbo *
* jens.dagerbo@swipnet.se *
* *
* 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 <tqlistview.h>
#include <tqheader.h>
#include <tqlabel.h>
#include <tqregexp.h>
#include <kdebug.h>
#include <tdeapplication.h>
#include <kurllabel.h>
#include "tdevplugin.h"
#include "projectmanager.h"
#include "plugincontroller.h"
#include "pluginselectdialog.h"
class PluginItem : public TQCheckListItem
{
public:
// name - "Name", label - "GenericName", info - "Comment"
PluginItem( TQListView * parent, TQString const & name, TQString const & label,
TQString const & info, TQString const url = TQString() )
: TQCheckListItem( parent, label, TQCheckListItem::CheckBox),
_name( name ), _info( info ), _url( url )
{}
TQString info() { return _info; }
TQString name() { return _name; }
TQString url() { return _url; }
private:
TQString _name;
TQString _info;
TQString _url;
};
PluginSelectDialog::PluginSelectDialog(TQWidget* parent, const char* name, bool modal, WFlags fl )
: PluginSelectDialogBase( parent,name, modal,fl )
{
plugin_list->setResizeMode( TQListView::LastColumn );
plugin_list->addColumn("");
plugin_list->header()->hide();
connect( plugin_list, TQT_SIGNAL( selectionChanged( TQListViewItem * ) ), this, TQT_SLOT( itemSelected( TQListViewItem * ) ) );
connect( urllabel, TQT_SIGNAL( leftClickedURL( const TQString & ) ), this, TQT_SLOT( openURL( const TQString & ) ) );
init();
}
PluginSelectDialog::~PluginSelectDialog()
{
}
void PluginSelectDialog::saveAsDefault()
{
kdDebug(9000) << k_funcinfo << endl;
ProfileEngine & engine = PluginController::getInstance()->engine();
Profile * profile = engine.findProfile( PluginController::getInstance()->currentProfile() );
profile->clearList( Profile::ExplicitDisable );
TQListViewItemIterator it( plugin_list );
while ( it.current() )
{
PluginItem * item = static_cast<PluginItem*>( it.current() );
if ( !item->isOn() )
{
profile->addEntry( Profile::ExplicitDisable, item->name() );
}
++it;
}
profile->save();
}
void PluginSelectDialog::openURL( const TQString & url )
{
kapp->invokeBrowser( url );
}
void PluginSelectDialog::itemSelected( TQListViewItem * item )
{
if ( ! item ) return;
PluginItem * pitem = static_cast<PluginItem*>( item );
plugin_description_label->setText( pitem->info() );
if ( pitem->url().isEmpty() )
{
urllabel->clear();
}
else
{
urllabel->setURL( pitem->url() );
urllabel->setText( pitem->url() );
}
}
void PluginSelectDialog::init( )
{
const TQValueList<TDevPlugin*> loadedPlugins = PluginController::getInstance()->loadedPlugins();
TQStringList loadedPluginDesktopNames;
TQValueList<TDevPlugin*>::ConstIterator it = loadedPlugins.begin();
while( it != loadedPlugins.end() )
{
loadedPluginDesktopNames << (*it)->instance()->instanceName();
++it;
}
kdDebug(9000) << " *** loadedPluginDesktopNames: " << loadedPluginDesktopNames << endl;
TDETrader::OfferList localOffers;
if ( ProjectManager::getInstance()->projectLoaded() )
{
localOffers = PluginController::getInstance()->engine().offers(
PluginController::getInstance()->currentProfile(), ProfileEngine::Project );
}
TDETrader::OfferList globalOffers = PluginController::getInstance()->engine().offers(
PluginController::getInstance()->currentProfile(), ProfileEngine::Global);
TDETrader::OfferList offers = localOffers + globalOffers;
for (TDETrader::OfferList::ConstIterator it = offers.begin(); it != offers.end(); ++it)
{
// parse out any existing url to make it clickable
TQString Comment = (*it)->comment();
TQRegExp re("\\bhttp://[\\S]*");
re.search( Comment );
Comment.replace( re, "" );
TQString url;
if ( re.pos() > -1 )
{
url = re.cap();
}
PluginItem *item = new PluginItem( plugin_list, (*it)->desktopEntryName(), (*it)->genericName(), Comment, url );
item->setOn( loadedPluginDesktopNames.contains( (*it)->desktopEntryName() ) );
kdDebug(9000) << (*it)->desktopEntryName() << " : " << (loadedPluginDesktopNames.contains( (*it)->desktopEntryName() ) ? "YES" : "NO" ) << endl;
}
TQListViewItem * first = plugin_list->firstChild();
if ( first )
{
plugin_list->setSelected( first, true );
}
}
TQStringList PluginSelectDialog::unselectedPluginNames( )
{
TQStringList unselectedPlugins;
TQListViewItem * item = plugin_list->firstChild();
while ( item )
{
PluginItem * pluginItem = static_cast<PluginItem*>( item );
if ( !pluginItem->isOn() )
{
unselectedPlugins << pluginItem->name();
}
item = item->nextSibling();
}
return unselectedPlugins;
}
#include "pluginselectdialog.moc"
// kate: space-indent off; indent-width 4; tab-width 4; show-tabs off;
|