SVN_SILENT made messages (.desktop file)
[kdeadmin.git] / kpackage / findf.cpp
blobe941f902c14e5ec3af0aadabb9ef0d368bd1737f
1 /*
2 ** Copyright (C) 1999,2000 Toivo Pedaste <toivo@ucs.uwa.edu.au>
3 **
4 */
6 /*
7 ** This program is free software; you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation; either version 2 of the License, or
10 ** (at your option) any later version.
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ** GNU General Public License for more details.
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program in a file called COPYING; if not, write to
19 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 ** MA 02110-1301, USA.
24 ** Bug reports and questions can be sent to kde-devel@kde.org
27 #include <QtGui/QLineEdit>
28 #include <QtGui/QPainter>
29 //Added by qt3to4:
30 #include <QtGui/QDragEnterEvent>
31 #include <QtGui/QLabel>
32 #include <QtGui/QVBoxLayout>
33 #include <QtGui/QFrame>
34 #include <QtGui/QGridLayout>
35 #include <QtGui/QResizeEvent>
36 #include <QtGui/QDropEvent>
37 #include <QtGui/QApplication>
39 #include <klocale.h>
40 #include <kdebug.h>
41 #include <k3urldrag.h>
42 #include <kiconloader.h>
44 #include "kpackage.h"
45 #include "managementWidget.h"
46 #include "findf.h"
47 #include "pkgInterface.h"
50 FindF::FindF(QWidget *parent)
51 : KDialog(parent)
53 setCaption(i18n("Find File") );
54 setButtons(User1 | Close );
55 setDefaultButton( User1 );
56 setButtonGuiItem( User1, KGuiItem(i18n("&Find"),"file-find") );
57 tick = UserIcon("ptick");
59 QFrame *page = new QFrame(this);
60 setMainWidget( page );
61 setFocusPolicy(Qt::StrongFocus);
63 QVBoxLayout* vtop = new QVBoxLayout( page );
64 vtop->setSpacing( KDialog::spacingHint() );
65 vtop->setMargin( KDialog::marginHint() );
66 vtop->setObjectName( "vtop" );
67 Q3GroupBox *frame1 = new Q3GroupBox(i18n("Find Package"), page, "frame1");
68 vtop->addWidget(frame1,1);
70 QGridLayout* gtop = new QGridLayout( frame1 );
71 // gtop->setMargin( KDialog::marginHint() );
72 gtop->setSpacing( KDialog::spacingHint() );
74 value = new QLineEdit( frame1 );
75 value->setObjectName( "value" );
76 connect(value,SIGNAL(textChanged ( const QString & )),this,SLOT(textChanged ( const QString & )));
77 value->setFocus();
79 QLabel *valueLabel = new QLabel(frame1);
80 valueLabel->setBuddy(value);
81 valueLabel->setText(i18n("Find:"));
82 valueLabel->setAlignment( Qt::AlignRight );
84 tab = new K3ListView( frame1 );
85 tab->setObjectName( "tab" );
86 connect(tab, SIGNAL(selectionChanged ( Q3ListViewItem * )),
87 this, SLOT(search( Q3ListViewItem * )));
88 tab->addColumn(i18n("Installed"),18);
89 tab->addColumn("",0); // Hidden column for package type
90 tab->addColumn(i18n("Package"),180);
91 tab->addColumn(i18n("File Name"),330);
92 tab->setAllColumnsShowFocus(true);
93 tab->setSorting(1);
95 if (kpinterface[0]->ifExe("apt-file")) {
96 searchAll = new QCheckBox(i18n("Also search uninstalled packages"), frame1);
97 searchAll->setObjectName("searchAll");
98 } else {
99 searchAll = new QCheckBox(i18n("Also search uninstalled packages (apt-file needs to be installed)"), frame1);
100 searchAll->setObjectName("searchAll");
101 if (hostName.isEmpty()) {
102 searchAll->setDisabled(true);
105 searchAll->setChecked(false);
108 gtop->addWidget(valueLabel, 0, 0);
109 gtop->addWidget(value, 0, 1);
110 gtop->addWidget(tab, 1, 0, 1, 2);
112 gtop->addWidget(searchAll, 2, 0);
114 connect(this, SIGNAL(user1Clicked()), this, SLOT(ok_slot()));
115 connect(this, SIGNAL(closeClicked()), this, SLOT(done_slot()));
116 enableButton(User1 , false);
117 show();
119 setAcceptDrops(true);
122 FindF::~FindF()
126 void FindF::disableSearchAll()
128 searchAll->setChecked(false);
129 searchAll->setEnabled(false);
132 void FindF::textChanged ( const QString & text)
134 enableButton(User1 , !text.isEmpty());
137 void FindF::ok_slot()
139 doFind(value->text());
142 void FindF::doFind(const QString &str)
144 QString t;
145 int cnt = 0;
147 bool all = searchAll->isChecked();
149 QApplication::setOverrideCursor( Qt::WaitCursor );
151 tab->clear();
153 for (int i = 0; i < kpinterfaceN; i++) {
154 const QStringList filelist = kpinterface[i]->FindFile(str, all);
156 // kDebug() << "FindF::doFind" << filelist.count() << "\n";
157 if (filelist.count() > 0) {
158 cnt++;
160 for ( QStringList::const_iterator it = filelist.begin(); it != filelist.end(); ++it ) {
161 if ((*it).indexOf("diversion by") >= 0) {
162 new Q3ListViewItem(tab, "", *it);
165 int t1 = (*it).indexOf('\t');
166 QString s1 = (*it).left(t1);
167 QString s2 = (*it).right((*it).length()-t1);
168 s2 = s2.trimmed();
170 Q3ListViewItem *ql = new Q3ListViewItem(tab, "", "", s1, s2);
172 QString tx = s1;
173 if (kpackage->management->dirInstPackages.value(tx)) {
174 ql->setPixmap(0,tick);
180 if (!cnt) {
181 new Q3ListViewItem(tab, "", i18n("--Nothing found--"));
184 QApplication::restoreOverrideCursor();
187 void FindF::done_slot()
189 hide();
192 void FindF::resizeEvent(QResizeEvent *){
195 void FindF::search(Q3ListViewItem *item)
197 int p;
199 QString s = item->text(3);
200 s = s.trimmed();
201 kDebug() << "searchF=" << s << "\n";
203 p = s.indexOf(',');
204 if (p > 0) {
205 s.truncate(p);
208 KpTreeListItem *k = kpackage->management->treeList->search(s ,item->text(1));
209 if (k)
210 kpackage->management->treeList->changePack(k);
213 void FindF::dragEnterEvent(QDragEnterEvent* e)
215 e->setAccepted(K3URLDrag::canDecode(e));
218 void FindF::dropEvent(QDropEvent *de) // something has been dropped
220 KUrl::List list;
221 if (!K3URLDrag::decode(de, list) || list.isEmpty())
222 return;
224 const KUrl &url = list.first();
226 if (url.isLocalFile()) {
227 QString file = url.path(KUrl::RemoveTrailingSlash);
228 value->setText(file);
229 doFind(file);
230 } else {
231 KpMsgE(i18n("Incorrect URL type"),false);
235 #include "findf.moc"