summaryrefslogtreecommitdiffstats
path: root/kpackage/findf.cpp
blob: bcb936f28dd399bae9ef376e0b924ae5f84a3235 (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
225
226
227
228
/*
** Copyright (C) 1999,2000 Toivo Pedaste <toivo@ucs.uwa.edu.au>
**
*/

/*
** 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.
**
** 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 General Public License
** along with this program in a file called COPYING; if not, write to
** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
** MA 02110-1301, USA.
*/

/*
** Bug reports and questions can be sent to kde-devel@kde.org
*/

#include "../config.h"

#include <tqlineedit.h>
#include <tqpainter.h> 

#include <tdelocale.h>
#include <kdebug.h>
#include <kurldrag.h>
#include <kiconloader.h>

#include "kpackage.h"
#include "managementWidget.h"
#include "findf.h"
#include "options.h"
#include "pkgInterface.h"

extern pkgInterface *kpinterface[];
extern Opts *opts;

FindF::FindF(TQWidget *parent)
    : KDialogBase(parent, "find_file", false,
		i18n("Find File"),
		User1 | Close, User1, true,
		KGuiItem(i18n("&Find"),"filefind"))
{
    tick = UserIcon("ptick");

    TQFrame *page = makeMainWidget();

    setFocusPolicy(TQ_StrongFocus);

    TQVBoxLayout* vtop = new TQVBoxLayout( page, 10, 10, "vtop");
    TQFrame *frame1 = new TQGroupBox(i18n("Find Package"), page, "frame1");
    vtop->addWidget(frame1,1);
 
    TQGridLayout* gtop = new TQGridLayout( frame1, 1, 1, 20 );
    //    gtop->setMargin( KDialog::marginHint() );
    gtop->setSpacing( KDialog::spacingHint() );

    value = new TQLineEdit( frame1, "value" );
    connect(value,TQT_SIGNAL(textChanged ( const TQString & )),this,TQT_SLOT(textChanged ( const TQString & )));
    value->setFocus();

    TQLabel *valueLabel = new TQLabel(value, i18n("Find:"), frame1);
    valueLabel->setAlignment( AlignRight );

    tab = new TDEListView(frame1, "tab");
    connect(tab, TQT_SIGNAL(selectionChanged ( TQListViewItem * )),
	    this, TQT_SLOT(search( TQListViewItem * )));
    tab->addColumn(i18n("Installed"),18);
    tab->addColumn(i18n("Type"),110);
    tab->addColumn("",0);   // Hidden column for package type
    tab->addColumn(i18n("Package"),180);
    tab->addColumn(i18n("File Name"),330);
    tab->setAllColumnsShowFocus(TRUE);
    tab->setSorting(1);

    if (kpackage->management->dirInstPackages->find("apt-file/deb")) {
      searchAll = new TQCheckBox(i18n("Also search uninstalled packages"), frame1, "searchAll");
    } else {
      searchAll = new TQCheckBox(i18n("Also search uninstalled packages (apt-file needs to be installed)"), frame1, "searchAll");
    }
    searchAll->setChecked(FALSE);

    gtop->addWidget(valueLabel, 0, 0);
    gtop->addWidget(value, 0, 1);
    gtop->addMultiCellWidget(tab, 1, 1, 0, 1);

    gtop->addWidget(searchAll, 2, 0);

    connect(this, TQT_SIGNAL(user1Clicked()), this, TQT_SLOT(ok_slot()));
    connect(this, TQT_SIGNAL(closeClicked()), this, TQT_SLOT(done_slot()));
    enableButton(User1 , false);
    show();

    setAcceptDrops(true);
}

FindF::~FindF()
{
}

void FindF::checkSearchAll() 
{
    // button not enabled if no package interface has search uninstalled
    // packages for files ability
    bool hasAll = FALSE;
    for (int i = 0; i < kpinterfaceN; i++) {
      if (kpinterface[i] && opts->handlePackage[i]) {
	if (kpinterface[i]->hasSearchAll) 
	  hasAll = TRUE;
      }
    }
    
    searchAll->setEnabled(hasAll);
}

void FindF::textChanged ( const TQString & text)
{
    enableButton(User1 , !text.isEmpty());
}

void FindF::ok_slot()
{
  doFind(value->text());
}

void FindF::doFind(const TQString &str)
{
  TQString t;
  int i, cnt = 0;

  bool all = searchAll->isChecked();

  TQApplication::setOverrideCursor( waitCursor );

  tab->clear();

  for (i = 0; i < kpinterfaceN; i++) {
    if (kpinterface[i] && opts->handlePackage[i]) {
      TQStringList filelist = kpinterface[i]->FindFile(str, all);

      if (filelist.count() > 0) {
	cnt++;

	for ( TQStringList::Iterator it = filelist.begin(); it != filelist.end(); ++it ) {
	  if ((*it).find("diversion by") >= 0) {
	    new TQListViewItem(tab, "", *it);
	  }

	  int t1 = (*it).find('\t');
	  TQString s1 = (*it).left(t1);
	  TQString s2 = (*it).right((*it).length()-t1);
	  s2 = s2.stripWhiteSpace();

	  TQListViewItem *ql = new TQListViewItem(tab, "", kpinterface[i]->name, kpinterface[i]->head, s1, s2);

	  TQString tx = s1 + kpinterface[i]->typeID;
	  if (kpackage->management->dirInstPackages->find(tx)) {
	    ql->setPixmap(0,tick);
	  }
	}
      }
    }
  }

  if (!cnt) {
    new TQListViewItem(tab, "", i18n("--Nothing found--"));
  }

  TQApplication::restoreOverrideCursor();
}

void FindF::done_slot()
{
  hide();
}

void FindF::resizeEvent(TQResizeEvent *){
}

void FindF::search(TQListViewItem *item)
{
  int p;

  TQString s = item->text(3);
  s = s.stripWhiteSpace();
  kdDebug() << "searchF=" << s << "\n";

  p = s.find(',');
  if (p > 0) {
    s.truncate(p);
  }

  KpTreeListItem *k =  kpackage->management->treeList->search(s ,item->text(2));
  if (k)
    kpackage->management->treeList->changePack(k);
}

void FindF::dragEnterEvent(TQDragEnterEvent* e)
{
  e->accept(KURLDrag::canDecode(e));
}

void FindF::dropEvent(TQDropEvent *de) // something has been dropped
{
  KURL::List list;
  if (!KURLDrag::decode(de, list) || list.isEmpty())
     return;

  const KURL &url = list.first();

  if (url.isLocalFile()) {
    TQString file = url.path(-1);
    value->setText(file);
    doFind(file);
  } else {
    KpMsgE(i18n("Incorrect URL type"),FALSE);
  }
}

#include "findf.moc"