New version of kfind, committing on behalf of "Eric Coquelle" <eric.coquelle@unice.fr>.

The kfind binary now uses the kfindpart at its core, thus removing code
duplication. This makes it necessary to have all of kfind in kdebase though,
since kfindpart links to libkonq and kfind links to kfindpart.

svn path=/trunk/kdebase/kfind/; revision=118426
This commit is contained in:
David Faure 2001-10-18 09:14:25 +00:00
parent 6ea7e9f92b
commit b334157c71
33 changed files with 3040 additions and 0 deletions

16
kfind/AUTHORS Normal file
View file

@ -0,0 +1,16 @@
kfind has been developed by :
Eric Coquelle <coquelle@caramail.com>
Beppe Grimaldi <grimalkin@ciaoweb.it>
Martin Hartig
Stephan Kulow <coolo@kde.org>
Mario Weilguni <mweilguni@sime.com>
Alex Zepeda <jazepeda@pacbell.net>
Miroslav Fl<46>r <flidr@kky.zcu.cz>
Harri Porten <porten@kde.org>
Dima Rogozin <dima@mercury.co.il>
Carsten Pfeiffer <pfeiffer@kde.org>
Hans Petter Bieker <bieker@kde.org>
Waldo Bastian <bastian@kde.org>

141
kfind/ChangeLog Normal file
View file

@ -0,0 +1,141 @@
Fri Jul 30 22:33:25 1999 Carsten Pfeiffer <pfeiffer@kde.org>
* kfwin.cpp, kfwin.h: The listview items show a mini-pixmap, like those
in kfiledialog. For now, they're static icons (only folder and document
icons), maybe we can show the correct icons for the mimetypes, later.
Also introduced drag-support, you can drag files from the list.
* kftabdlg.cpp: accept Key_Enter to start the search, too.
1999-06-13 Harri Porten <porten@kde.org>
* kftabdlg.cpp: introduced flexible geometry managment. Patch provided
by Dima Rogozin <dima@mercury.co.il>.
1999-04-30 Harri Porten <porten@kde.org>
* kftabdlg.cpp: Default to '*' when no filenames are specified and
allow case insensitive text search. Patch provided by Dima Rogozin
<dima@mercury.co.il>.
1999-04-06 Harri Porten <porten@kde.org>
* kfind.cpp: replaced simple delete and free() with delete [] iBuffer
1998-12-07 Mario Weilguni <mweilguni@kde.org>
* made it work with Qt 2.0
1998-12-07 Alex Zepeda <garbanzo@hooked.net>
* kfindtop.cpp: Commented out _height, as it's not used.
1998-11-30 Miroslav Flídr <flidr@kky.zcu.cz>
* Dissabled multiple selection in view because it was not fully
handled
* Fixed problem in nameBox, dirBox combos which caused improper
find query generation (it is still neccesary to fix multiplication of
list entries)
1998-10-23 Alex Zepeda <garbanzo@hooked.net>
* LICENSE: remove it, it's redundant.
* kfind/README: Tidy up, and mention inclusion in kdebase.
ver. 0.4.1: Mario Weilguni <mweilguni@kde.org>
* temporary files are no longer needed
* found files are now shown while searching
* KDE compliant "Help" menu
* max-/min-size box is now disabled per default
* GUI is disabled while searching, makes it easier to see
progress
* kfind compiles now without warnings with -Wall
* result list is now scrollable without having the focus (only page
up and page down)
* moc files are now #included in moc.cpp instead of compiling
separate files. Speeds up compilation and makes binary smaller
* file patterns are remembered between sessions
* introduced new filetypes for searching: files, folders,
symlinks, special files, executables, suid executables
* better keyboard support
ver. 0.4: Mario Weilguni <mweilguni@kde.org>
* introduced this ChangeLog
* kfind now uses KShellProcess instead of KProcess, makes
regular expression search possible with egrep/xargs
* kftabdlg.cpp: tab-dialog isn't closed anymore if Escape key
is pressed
* kfind can now search for contained text (with egrep)
* "Select All" and "Invert Selection" work now as expected
* "Copy" copies the currently selected items to the X11 selection
* "Unselect All" added for completeness
ver. 0.3.4:
o removed some resizing problems
o kfinds icons now uses only 16 color
o mimetype browser removed from preferences
(something like that should be in kcc)
o kfind sets icon for kwmII
ver. 0.3.3:
o uses KProcess
o supports other languages then english (at this time german and czech)
ver. 0.3.2:
o uses KTopLevelWidget and KToolBar
o new documentations
ver. 0.3.1:
o new documentation contributed by Mark Roberts
ver. 0.3:
o entry Open in File menu or doubleclick on file executes default binding
o removed bug causing segfaults
ver. 0.2.9:
o uses of autoconf
o you can specify searched directory as kfind argument
o added Icon entry in all provided filetypes (some were
missing this entry and kfm didn't liked it)
ver. 0.2.8:
o kfind is now KDE AWARE application!!
o uses libkde0.7 (=> kmsgbox and ktabctl removed from kfind distribution)
o uses filetypes introduced by Torben Weis for kfm (kfind installs
some more filetypes)
o it is possible to store files in archives
o preferences dialog added
- it is possible to determine filename for results saving
- it is possible to browse available filetypes details
- it is possible to browse available archivers details
(in next version you will be able to change the details)
o calls kfm for properties dialog
o menu entry "remove" removed (kfm properties dialog does the job)
o removed some bugs
ver. 0.2.6:
o reflects changes made by Martin Hartig (known as version 0.2.1)
ver. 0.2.5:
o implemented dir selection box (it is actually a littlebit changed
and striped down version of QFileDialog)
o delete, rename, properties functions are implemented
o function "Open containing folder" implemented (it calls KFM)
o search results are now saved in file ~/.kfind-results.html
(I finally recognized this is better choice than plain text file)
o removed nasty bug causing segfaults when compiler optimization were
used
o improved Makefile
ver. 0.2:
o all in kfind available options work now ;-))
o better calling of find. It's now separate process => interface isn't
blocked anymore during searching
ver. 0.1: first official release

30
kfind/Makefile.am Normal file
View file

@ -0,0 +1,30 @@
#Global section
METASOURCES = AUTO
EXTRA_DIST = DESCRIPTION
SUBDIRS = pics
# set the include path for X, qt and KDE
INCLUDES= $(all_includes)
#This section is kfindpart
kde_module_LTLIBRARIES = libkfindpart.la
libkfindpart_la_SOURCES = kftabdlg.cpp kfind.cpp kquery.cpp kdatecombo.cpp kfindpart.cpp
libkfindpart_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN)
libkfindpart_la_LIBADD = $(LIB_KPARTS) $(top_builddir)/libkonq/libkonq.la
noinst_HEADERS = kftabdlg.h kfind.h version.h kquery.h kdatecombo.h
kde_services_DATA = kfindpart.desktop
kde_servicetypes_DATA = findpart.desktop
messages:
$(XGETTEXT) *.cpp *.h -o $(podir)/kfindpart.pot
#And this is for kfind
bin_PROGRAMS = kfind
kfind_SOURCES = kfwin.cpp kfinddlg.cpp main.cpp
kfind_LDADD = libkfindpart.la $(top_builddir)/libkonq/libkonq.la
# the library search path.
kfind_LDFLAGS = $(all_libraries) $(KDE_RPATH)

24
kfind/README Normal file
View file

@ -0,0 +1,24 @@
kfind
=====
Kfind is a graphical replacement for the utility `find' inspired by
the find utility from NT.
At this time it is fully functional. All options available in kfind
are working. You can save the results, delete, change properties of
found files/directories and ask konqueror to open the directory
containing this file or execute default binding.
THANKS
------
I want to thank Alexander Sanda <alex@darkstar.ping.at> for making
KTabCtl which is used in Kfind and Torben Weis
<weis@stud.uni-frankfurt.de> for his wonderful file manager konqueror.
I hope you will find this program somehow useful and I would
appreciate any suggestions and comments.
Miroslav Flídr
<flidr@kky.zcu.cz>

13
kfind/TODO Normal file
View file

@ -0,0 +1,13 @@
TODO
====
o support the more esoterical features of find
o support for finding files belonging to somebody
DONE:
o drag found files to somewhere
o some layout managment
o context menus
o get preference dialog to work
o find pattern history

45
kfind/findpart.desktop Normal file
View file

@ -0,0 +1,45 @@
[Desktop Entry]
Type=ServiceType
X-KDE-ServiceType=Konqueror/FindPart
X-KDE-Derived=Browser/View
Name=Find Part
Name[af]=vind deel
Name[ara]=ابحث عن جزء
Name[az]=Parça tap
Name[bg]=Търсене по съдържание
Name[cs]=Najít soubor
Name[da]=Find del
Name[de]=Einbettbares Programm suchen
Name[eo]=Trovokomponento
Name[es]=Buscar parte
Name[et]=Failide otsimise komponent
Name[fi]=Etsi osa
Name[fr]=Composant de recherche
Name[he]=רכיב חיפוש
Name[hu]=Keresési objektum
Name[id]=Cari bagian
Name[ind]=Cari bagian
Name[is]=Finna hluta
Name[it]=Part per la ricerca
Name[ko]=
Name[lt]=Surasti dalį
Name[lv]=Meklēt Daļu
Name[mt]=Sib Parti
Name[nl]=Part zoeken
Name[no]=Finn del
Name[no_NY]=Finn del
Name[pl]=Moduł szukania
Name[pt]=Componente de Pesquisa
Name[pt_BR]=Encontrar parte
Name[ru]=Поиск по содержимому
Name[sk]=Nájsť Part
Name[sl]=Najdi del
Name[sr]=Pronađi deo
Name[sv]=Sökdel
Name[ta]=À̾¢¨Âì ¸ñÎÀ¢Ê
Name[th]=
Name[tr]=Parça bul
Name[vi]=Tìm phn
Name[xxx]=xx
Name[zh_CN.GB2312]=
Name[zh_TW.Big5]=

89
kfind/kdatecombo.cpp Normal file
View file

@ -0,0 +1,89 @@
/***********************************************************************
*
* kdatecombo.cpp
*
***********************************************************************/
#include <kglobal.h>
#include <klocale.h>
#include <kdatepik.h>
#include <kdatetbl.h>
#include "kdatecombo.h"
#include "kdatecombo.moc"
KDateCombo::KDateCombo(QWidget *parent, const char *name ) : QComboBox(FALSE, parent,name)
{
QDate date = QDate::currentDate();
initObject(date, parent, name);
}
KDateCombo::KDateCombo(const QDate & date, QWidget *parent=0, const char *name=0) : QComboBox(FALSE, parent,name)
{
initObject(date, parent, name);
}
void KDateCombo::initObject(const QDate & date, QWidget *parent=0, const char *name=0)
{
clearValidator();
popupFrame = new KPopupFrame(this, "popupFrame");
datePicker = new KDatePicker(popupFrame, date, "datePicker");
datePicker->setMinimumSize(datePicker->sizeHint());
popupFrame->setMainWidget(datePicker);
setDate(date);
connect(datePicker, SIGNAL(dateEntered(QDate)), this, SLOT(dateEnteredEvent(QDate)));
}
KDateCombo::~KDateCombo()
{
delete datePicker;
delete popupFrame;
}
QString KDateCombo::date2String(const QDate & date)
{
return(KGlobal::locale()->formatDate(date, true));
}
QDate & KDateCombo::string2Date(const QString & str, QDate *qd)
{
return *qd = KGlobal::locale()->readDate(str);
}
QDate & KDateCombo::getDate(QDate *currentDate)
{
return string2Date(currentText(), currentDate);
}
bool KDateCombo::setDate(const QDate & newDate)
{
if (newDate.isValid())
{
if (count())
clear();
insertItem(date2String(newDate));
return TRUE;
}
return FALSE;
}
void KDateCombo::dateEnteredEvent(QDate newDate)
{
popupFrame->hide();
setDate(newDate);
}
void KDateCombo::mousePressEvent (QMouseEvent * e)
{
if (e->button() & QMouseEvent::LeftButton)
if (rect().contains( e->pos()))
{
QDate tempDate;
getDate(& tempDate);
datePicker->setDate(tempDate);
popupFrame->popup(mapToGlobal(QPoint(0, height())));
//datePicker->setFocus();
}
}

48
kfind/kdatecombo.h Normal file
View file

@ -0,0 +1,48 @@
/***********************************************************************
*
* kdatecombo.h
*
***********************************************************************/
#ifndef KDATECOMBO_H
#define KDATECOMBO_H
#include <qwidget.h>
#include <qcombobox.h>
#include <qdatetime.h>
/**
*@author Beppe Grimaldi
*/
class KDatePicker;
class KPopupFrame;
class KDateCombo : public QComboBox {
Q_OBJECT
public:
KDateCombo(QWidget *parent=0, const char *name=0);
KDateCombo(const QDate & date, QWidget *parent=0, const char *name=0);
~KDateCombo();
QDate & getDate(QDate *currentDate);
bool setDate(const QDate & newDate);
private:
KPopupFrame * popupFrame;
KDatePicker * datePicker;
void initObject(const QDate & date, QWidget *parent, const char *name);
QString date2String(const QDate &);
QDate & string2Date(const QString &, QDate * );
protected:
virtual void mousePressEvent (QMouseEvent * e);
protected slots:
void dateEnteredEvent(QDate);
};
#endif

176
kfind/kfind.cpp Normal file
View file

@ -0,0 +1,176 @@
/***********************************************************************
*
* Kfind.cpp
*
* This is KFind, released under GPL
*
* 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.
*
* KFind (c) 1998-2000 The KDE Developers
Martin Hartig
Stephan Kulow <coolo@kde.org>
Mario Weilguni <mweilguni@sime.com>
Alex Zepeda <jazepeda@pacbell.net>
Miroslav Flídr <flidr@kky.zcu.cz>
Harri Porten <porten@kde.org>
Dima Rogozin <dima@mercury.co.il>
Carsten Pfeiffer <pfeiffer@kde.org>
Hans Petter Bieker <bieker@kde.org>
Waldo Bastian <bastian@kde.org>
Beppe Grimaldi <grimalkin@ciaoweb.it>
Eric Coquelle <coquelle@caramail.com>
**********************************************************************/
#include <qpushbutton.h>
#include <qlayout.h>
#include <qvbox.h>
#include <kdialog.h>
#include <kdebug.h>
#include <klocale.h>
#include <kseparator.h>
#include <qlineedit.h>
#include <qcheckbox.h>
//#include <kstatusbar.h>
#include "kftabdlg.h"
#include "kquery.h"
#include "kfind.moc"
Kfind::Kfind(QWidget *parent, const char *name)
: QWidget( parent, name )
{
kdDebug() << "Kfind::Kfind " << this << endl;
QBoxLayout * mTopLayout = new QBoxLayout( this, QBoxLayout::LeftToRight,
KDialog::marginHint(), KDialog::spacingHint() );
// create tabwidget
tabWidget = new KfindTabWidget( this );
mTopLayout->addWidget(tabWidget);
// create separator
KSeparator * mActionSep = new KSeparator( this );
mActionSep->setFocusPolicy( QWidget::ClickFocus );
mActionSep->setOrientation( QFrame::VLine );
mTopLayout->addWidget(mActionSep);
// create button box
QWidget * mButtonBox = new QVBox( this );
mTopLayout->addWidget(mButtonBox);
mSearch = new QPushButton( i18n("&Find"), mButtonBox );
connect( mSearch, SIGNAL(clicked()), this, SLOT( startSearch() ) );
mStop = new QPushButton( i18n("Stop"), mButtonBox );
connect( mStop, SIGNAL(clicked()), this, SLOT( stopSearch() ) );
mSave = new QPushButton( i18n("Save..."), mButtonBox );
connect( mSave, SIGNAL(clicked()), this, SLOT( saveResults() ) );
QPushButton * mClose = new QPushButton( i18n("&Close"), mButtonBox );
connect( mClose, SIGNAL(clicked()), this, SIGNAL( destroyMe() ) );
mSearch->setEnabled(true); // Enable "Search"
mStop->setEnabled(false); // Disable "Stop"
mSave->setEnabled(false); // Disable "Save..."
}
Kfind::~Kfind()
{
stopSearch();
kdDebug() << "Kfind::~Kfind" << endl;
}
void Kfind::setURL( const KURL &url )
{
tabWidget->setURL( url );
}
void Kfind::startSearch()
{
tabWidget->setQuery(query);
emit started();
//emit resultSelected(false);
//emit haveResults(false);
mSearch->setEnabled(false); // Disable "Search"
mStop->setEnabled(true); // Enable "Stop"
mSave->setEnabled(false); // Disable "Save..."
tabWidget->beginSearch();
query->start();
}
void Kfind::stopSearch()
{
// will call KFindPart::slotResult, which calls searchFinished here
query->kill();
}
/*
void Kfind::newSearch()
{
// WABA: Not used any longer?
stopSearch();
tabWidget->setDefaults();
emit haveResults(false);
emit resultSelected(false);
setFocus();
}
*/
void Kfind::searchFinished()
{
mSearch->setEnabled(true); // Enable "Search"
mStop->setEnabled(false); // Disable "Stop"
// ## TODO mSave->setEnabled(true); // Enable "Save..."
tabWidget->endSearch();
setFocus();
}
void Kfind::saveResults()
{
// TODO
}
void Kfind::setFocus()
{
tabWidget->setFocus();
}
void Kfind::saveState( QDataStream *stream )
{
query->kill();
*stream << tabWidget->nameBox->currentText();
*stream << tabWidget->dirBox->currentText();
*stream << tabWidget->typeBox->currentItem();
*stream << tabWidget->textEdit->text();
*stream << ( tabWidget->subdirsCb->isChecked() ? 0 : 1 );
}
void Kfind::restoreState( QDataStream *stream )
{
QString namesearched, dirsearched,containing;
int typeIdx;
int subdirs;
*stream >> namesearched;
*stream >> dirsearched;
*stream >> typeIdx;
*stream >> containing;
*stream >> subdirs;
tabWidget->nameBox->insertItem( namesearched, 0);
tabWidget->dirBox->insertItem ( dirsearched, 0);
tabWidget->typeBox->setCurrentItem(typeIdx);
tabWidget->textEdit->setText ( containing );
tabWidget->subdirsCb->setChecked( ( subdirs==0 ? true : false ));
}

60
kfind/kfind.h Normal file
View file

@ -0,0 +1,60 @@
/***********************************************************************
*
* Kfind.h
*
***********************************************************************/
#ifndef KFIND_H
#define KFIND_H
#include <qwidget.h>
#include <kfileitem.h>
class QString;
class QPushButton;
class KQuery;
class KURL;
class KfindTabWidget;
class Kfind: public QWidget
{
Q_OBJECT
public:
Kfind(QWidget * parent = 0, const char * name = 0);
~Kfind();
void setURL( const KURL &url );
void setQuery(KQuery * q) { query = q; }
void searchFinished();
void saveState( QDataStream *stream );
void restoreState( QDataStream *stream );
public slots:
void startSearch();
void stopSearch();
//void newSearch();
void saveResults();
signals:
void haveResults(bool);
void resultSelected(bool);
void started();
void destroyMe();
private:
void setFocus();
KfindTabWidget *tabWidget;
QPushButton *mSearch;
QPushButton *mStop;
QPushButton *mSave;
KQuery *query;
};
#endif

202
kfind/kfinddlg.cpp Normal file
View file

@ -0,0 +1,202 @@
/***********************************************************************
*
* Kfinddlg.cpp
*
**********************************************************************/
#include <qlayout.h>
#include <klocale.h>
#include <kglobal.h>
#include <kstatusbar.h>
#include <kmessagebox.h>
#include <kdebug.h>
#include <kaboutapplication.h>
#include "kftabdlg.h"
#include "kquery.h"
#include "kfwin.h"
#include "kfinddlg.h"
#include "kfinddlg.moc"
KfindDlg::KfindDlg(const KURL & url, QWidget *parent, const char *name)
: KDialogBase( Plain, QString::null,
User1 | User2 | User3 | Apply | Close | Help, User1,
parent, name, true, true,
i18n("&Find"), i18n("Stop"), i18n("Save...") )
{
QWidget::setCaption( i18n("Find Files" ) );
setButtonBoxOrientation(Vertical);
enableButton(User1, true); // Enable "Search"
enableButton(User2, false); // Disable "Stop"
enableButton(User3, false); // Disable "Save..."
setEscapeButton(User2);
setButtonApplyText(i18n("About"));
isResultReported = false;
QFrame *frame = plainPage();
// create tabwidget
tabWidget = new KfindTabWidget( frame, "dialog");
// prepare window for find results
win = new KfindWindow(frame,"window");
mStatusBar = new KStatusBar(frame);
mStatusBar->insertFixedItem(i18n("AMiddleLengthText..."), 0, true);
setStatusMsg(i18n("Ready."));
mStatusBar->setItemAlignment(0, AlignLeft | AlignVCenter);
mStatusBar->insertItem(QString::null, 1, 1, true);
mStatusBar->setItemAlignment(1, AlignLeft | AlignVCenter);
QVBoxLayout *vBox = new QVBoxLayout(frame);
vBox->addWidget(tabWidget, 0);
vBox->addWidget(win, 1);
vBox->addWidget(mStatusBar, 0);
connect(this, SIGNAL(user1Clicked()),
this, SLOT(startSearch()));
connect(this, SIGNAL(user2Clicked()),
this, SLOT(stopSearch()));
connect(this, SIGNAL(user3Clicked()),
win, SLOT(saveResults()));
connect(win ,SIGNAL(resultSelected(bool)),
this,SIGNAL(resultSelected(bool)));
connect(this, SIGNAL( applyClicked() ), this, SLOT(about()));
query = new KQuery(frame);
connect(query, SIGNAL(addFile(const KFileItem*/*FIXME,const QString&*/)),
SLOT(addFile(const KFileItem*/*FIXME,const QString&*/)));
connect(query, SIGNAL(result(int)), SLOT(slotResult(int)));
aboutWin = new KAboutApplication(this, "about", true);
}
KfindDlg::~KfindDlg()
{
stopSearch();
}
void KfindDlg::closeEvent(QCloseEvent *)
{
slotClose();
}
void KfindDlg::setProgressMsg(const QString &msg)
{
mStatusBar->changeItem(msg, 1);
}
void KfindDlg::setStatusMsg(const QString &msg)
{
mStatusBar->changeItem(msg, 0);
}
void KfindDlg::startSearch()
{
tabWidget->setQuery(query);
isResultReported = false;
// Reset count
setProgressMsg(i18n("%1 files found").arg(0));
setStatusMsg(i18n("Searching..."));
emit resultSelected(false);
emit haveResults(false);
enableButton(User1, false); // Disable "Search"
enableButton(User2, true); // Enable "Stop"
enableButton(User3, false); // Disable "Save..."
win->beginSearch(KURL()/*FIXMEquery->url()*/);
tabWidget->beginSearch();
query->start();
}
void KfindDlg::stopSearch()
{
query->kill();
}
void KfindDlg::newSearch()
{
// WABA: Not used any longer?
stopSearch();
tabWidget->setDefaults();
emit haveResults(false);
emit resultSelected(false);
setFocus();
}
void KfindDlg::slotResult(int errorCode)
{
if (errorCode == 0)
setStatusMsg(i18n("Ready."));
else if (errorCode == KIO::ERR_USER_CANCELED)
setStatusMsg(i18n("Aborted."));
else if (errorCode == KIO::ERR_DOES_NOT_EXIST)
{
setStatusMsg(i18n("Error."));
KMessageBox::sorry( this, i18n("Could not find the specified directory."));
}
else
{
kdDebug()<<"KIO error code: "<<errorCode<<endl;
setStatusMsg(i18n("Error."));
};
enableButton(User1, true); // Enable "Search"
enableButton(User2, false); // Disable "Stop"
enableButton(User3, true); // Enable "Save..."
win->endSearch();
tabWidget->endSearch();
setFocus();
}
void KfindDlg::addFile(const KFileItem* item/*FIXME, const QString& matchingLine*/)
{
win->insertItem(*item, ""/*,matchingLine*/);
if (!isResultReported)
{
emit haveResults(true);
isResultReported = true;
}
int count = win->childCount();
QString str;
if (count == 1)
str = i18n("1 file found");
else
str = i18n("%1 files found")
.arg(KGlobal::locale()->formatNumber(count, 0));
setProgressMsg(str);
}
void KfindDlg::setFocus()
{
tabWidget->setFocus();
}
void KfindDlg::copySelection()
{
win->copySelection();
}
void KfindDlg::about ()
{
aboutWin->show(this);
//delete aboutWin;
}

61
kfind/kfinddlg.h Normal file
View file

@ -0,0 +1,61 @@
/***********************************************************************
*
* KfindDlg.h
*
***********************************************************************/
#ifndef KFINDDLG_H
#define KFINDDLG_H
#include <kdialogbase.h>
class QString;
class KQuery;
class KURL;
class KFileItem;
class KfindTabWidget;
class KfindWindow;
class KStatusBar;
class KAboutApplication;
class KfindDlg: public KDialogBase
{
Q_OBJECT
public:
KfindDlg(const KURL & url, QWidget * parent = 0, const char * name = 0);
~KfindDlg();
void copySelection();
void setStatusMsg(const QString &);
void setProgressMsg(const QString &);
public slots:
void startSearch();
void stopSearch();
void newSearch();
void addFile(const KFileItem* item/*FIXME, const QString& matchingLine*/);
void setFocus();
void slotResult(int);
// void slotSearchDone();
void about ();
signals:
void haveResults(bool);
void resultSelected(bool);
private:
void closeEvent(QCloseEvent *);
KfindTabWidget *tabWidget;
KfindWindow * win;
KAboutApplication * aboutWin;
bool isResultReported;
KQuery *query;
KStatusBar *mStatusBar;
};
#endif

211
kfind/kfindpart.cpp Normal file
View file

@ -0,0 +1,211 @@
/* This file is part of the KDE projects
Copyright (C) 2000 David Faure <faure@kde.org>
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; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "kfind.h"
#include "kfindpart.h"
#include "kquery.h"
#include <kparts/factory.h>
#include <kdebug.h>
#include <qdir.h>
#include <kinstance.h>
class KonqDirPart;
class KFindFactory : public KParts::Factory
{
public:
KFindFactory()
{
s_instance = 0;
}
virtual ~KFindFactory()
{
delete s_instance;
s_instance = 0;
}
virtual KParts::Part* createPartObject( QWidget *parentWidget, const char *,
QObject *parent, const char *name, const char*,
const QStringList &args )
{
return new KFindPart( parentWidget, parent, name,args.first() );
}
static KInstance *instance()
{
if ( !s_instance )
s_instance = new KInstance( "kfindpart" );
return s_instance;
}
private:
static KInstance *s_instance;
};
KInstance *KFindFactory::s_instance = 0;
extern "C"
{
void *init_libkfindpart()
{
return new KFindFactory;
}
};
KFindPart::KFindPart( QWidget * parentWidget, QObject *parent, const char *name , const QString& mode)
: KonqDirPart (parent, name )/*KParts::ReadOnlyPart*/
{
setInstance( KFindFactory::instance() );
setBrowserExtension( new KFindPartBrowserExtension(this) );
kdDebug() << "KFindPart::KFindPart " << this << endl;
m_kfindWidget = new Kfind( parentWidget, name );
m_kfindWidget->setMaximumHeight(m_kfindWidget->minimumSizeHint().height());
const KFileItem *item = ((KonqDirPart*)parent)->currentItem();
kdDebug() << "Kfind: currentItem: " << ( item ? item->url().path().local8Bit() : QString("null") ) << endl;
QDir d;
if( item && d.exists( item->url().path() ))
m_kfindWidget->setURL( item->url() );
setWidget( m_kfindWidget );
connect( m_kfindWidget, SIGNAL(started()),
this, SLOT(slotStarted()) );
connect( m_kfindWidget, SIGNAL(destroyMe()),
this, SLOT(slotDestroyMe()) );
//setXMLFile( "kfind.rc" );
query = new KQuery(this);
connect(query, SIGNAL(addFile(const KFileItem *)),
SLOT(addFile(const KFileItem *)));
connect(query, SIGNAL(result(int)),
SLOT(slotResult(int)));
m_kfindWidget->setQuery(query);
m_bShowsResult = false;
m_lstFileItems.setAutoDelete( true );
}
KFindPart::~KFindPart()
{
}
bool KFindPart::openURL( const KURL &url )
{
m_kfindWidget->setURL( url );
return true;
}
void KFindPart::slotStarted()
{
kdDebug() << "KFindPart::slotStarted" << endl;
m_bShowsResult = true;
m_lstFileItems.clear(); // clear our internal list
emit started();
emit clear();
}
void KFindPart::addFile(const KFileItem *item)
{
m_lstFileItems.append( item );
KFileItemList lstNewItems;
lstNewItems.append(item);
emit newItems(lstNewItems);
/*
win->insertItem(item);
if (!isResultReported)
{
emit haveResults(true);
isResultReported = true;
}
*/
}
void KFindPart::slotResult(int errorCode)
{
if (errorCode == 0)
emit finished();
//setStatusMsg(i18n("Ready."));
else if (errorCode == KIO::ERR_USER_CANCELED)
emit canceled();
//setStatusMsg(i18n("Aborted."));
else
emit canceled(); // TODO ?
//setStatusMsg(i18n("Error."));
m_kfindWidget->searchFinished();
}
void KFindPart::slotDestroyMe()
{
m_kfindWidget->stopSearch();
emit clear(); // this is necessary to clear the delayed-mimetypes items list
m_lstFileItems.clear(); // clear our internal list
emit findClosed();
}
void KFindPart::saveKFindState( QDataStream *stream )
{
m_kfindWidget->saveState( stream );
//Now we'll save the search result
KFileItem *fileitem=m_lstFileItems.first();
*stream << m_lstFileItems.count();
while(fileitem!=NULL)
{
*stream << fileitem->url();
fileitem=m_lstFileItems.next();
}
}
void KFindPart::restoreKFindState( QDataStream *stream )
{
int nbitems;
int i;
KURL itemUrl;
m_kfindWidget->restoreState( stream );
*stream >> nbitems;
slotStarted();
for(i=0;i<nbitems;i++)
{
*stream >> itemUrl;
addFile(new KFileItem(itemUrl,"",0));
}
emit finished();
}
KFindPartBrowserExtension::KFindPartBrowserExtension( KFindPart *findPart )
: KParts::BrowserExtension( findPart )
{
m_findPart = findPart;
m_bSaveViewPropertiesLocally = false;
}
#include "kfindpart.moc"

50
kfind/kfindpart.desktop Normal file
View file

@ -0,0 +1,50 @@
[Desktop Entry]
Type=Service
Name=Find Part
Name[af]=vind deel
Name[ara]=ابحث عن جزء
Name[az]=Parça tap
Name[bg]=Търсене по съдържание
Name[cs]=Najít soubor
Name[da]=Find del
Name[de]=Einbettbares Programm suchen
Name[eo]=Trovokomponento
Name[es]=Buscar parte
Name[et]=Failide otsimise komponent
Name[fi]=Etsi osa
Name[fr]=Composant de recherche
Name[he]=רכיב חיפוש
Name[hu]=Keresési objektum
Name[id]=Cari bagian
Name[ind]=Cari bagian
Name[is]=Finna hluta
Name[it]=Part per la ricerca
Name[ko]=
Name[lt]=Surasti dalį
Name[lv]=Meklēt Daļu
Name[mt]=Sib Parti
Name[nl]=Part zoeken
Name[no]=Finn del
Name[no_NY]=Finn del
Name[pl]=Moduł szukania
Name[pt]=Componente de Pesquisa
Name[pt_BR]=Encontrar parte
Name[ru]=Поиск по содержимому
Name[sk]=Nájsť Part
Name[sl]=Najdi del
Name[sr]=Pronađi deo
Name[sv]=Sökdel
Name[ta]=À̾¢¨Âì ¸ñÎÀ¢Ê
Name[th]=
Name[tr]=Parça bul
Name[vi]=Tìm phn
Name[xxx]=xx
Name[zh_CN.GB2312]=
Name[zh_TW.Big5]=
MimeType=
ServiceTypes=Konqueror/FindPart
X-KDE-Library=libkfindpart
X-KDE-BrowserView-AllowAsDefault=true
X-KDE-BrowserView-HideFromMenus=true
X-KDE-BrowserView-PassiveMode=true
InitialPreference=10

126
kfind/kfindpart.h Normal file
View file

@ -0,0 +1,126 @@
/* This file is part of the KDE projects
Copyright (C) 2000 David Faure <faure@kde.org>
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; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef kfindpart__h
#define kfindpart__h
#include <kparts/browserextension.h>
#include <kparts/part.h>
#include <kfileitem.h>
#include <kdebug.h>
#include <qptrlist.h>
#include <konq_dirpart.h>
class KQuery;
//added
class KonqPropsView;
class KonqDirLister;
class KonqFileItem;
class KAction;
class KToggleAction;
class KActionMenu;
class QIconViewItem;
class IconViewBrowserExtension;
//end added
class KFindPart : public KonqDirPart//KParts::ReadOnlyPart
{
friend class KFindPartBrowserExtension;
Q_OBJECT
Q_PROPERTY( bool showsResult READ showsResult )
public:
KFindPart( QWidget * parentWidget, QObject *parent, const char *name, const QString& mode );
virtual ~KFindPart();
virtual bool openURL( const KURL &url );
virtual bool openFile() { return false; }
bool showsResult() const { return m_bShowsResult; }
/* Save everything in the dialog box, useful for the "back" function of konqueror */
void saveKFindState( QDataStream *stream );
void restoreKFindState( QDataStream *stream );
// "Cut" icons : disable those whose URL is in lst, enable the rest //added for konqdirpart
virtual void disableIcons( const KURL::List & ){};
virtual const KFileItem * currentItem(){return 0;};
signals:
// Konqueror connects directly to those signals
void started(); // started a search
void clear(); // delete all items
void newItems(const KFileItemList&); // found this/these item(s)
void finished(); // finished searching
void canceled(); // the user canceled the search
void findClosed(); // close us
protected slots:
void slotStarted();
void slotDestroyMe();
void addFile(const KFileItem *item);
void slotResult(int errorCode);
// slots connected to the directory lister //added for konqdirpart
// virtual void slotStarted();
virtual void slotCanceled(){};
virtual void slotCompleted(){};
virtual void slotNewItems( const KFileItemList& ){};
virtual void slotDeleteItem( KFileItem * ){};
virtual void slotRefreshItems( const KFileItemList& ){};
virtual void slotClear(){};
virtual void slotRedirection( const KURL & ){};
private:
Kfind * m_kfindWidget;
KQuery *query;
bool m_bShowsResult; // whether the dirpart shows the results of a search or not
/**
* The internal storage of file items
*/
QPtrList<KFileItem> m_lstFileItems;
};
/* This class will be used to save the kfind dialog state and
the search result. These will be restored when the user press the
"back" button
*/
class KFindPartBrowserExtension : public KParts::BrowserExtension
{
Q_OBJECT
friend class KFindPart;
public:
KFindPartBrowserExtension( KFindPart *findPart );
virtual void saveState( QDataStream &stream )
{
KParts::BrowserExtension::saveState( stream );
m_findPart->saveKFindState( &stream );
}
virtual void restoreState( QDataStream &stream )
{
KParts::BrowserExtension::restoreState( stream );
m_findPart->restoreKFindState( &stream );
}
private:
KFindPart *m_findPart;
bool m_bSaveViewPropertiesLocally;
};
#endif

178
kfind/kfindpart.kdevprj Normal file
View file

@ -0,0 +1,178 @@
[./AUTHORS]
dist=true
install=false
install_location=
type=DATA
[./ChangeLog]
dist=true
install=false
install_location=
type=DATA
[./Makefile.am]
files=./AUTHORS,./ChangeLog,./README,./TODO,./findpart.desktop,./kfind.cpp,./kfind.h,./kfindpart.cpp,./kfindpart.desktop,./kfindpart.h,./kftabdlg.cpp,./kftabdlg.h,./kquery.cpp,./kquery.h,./version.h,./kfindpart.kdevprj,
sub_dirs=pics,
type=normal
[./README]
dist=true
install=false
install_location=
type=DATA
[./TODO]
dist=true
install=false
install_location=
type=DATA
[./findpart.desktop]
dist=true
install=false
install_location=
type=DATA
[./kfind.cpp]
dist=true
install=false
install_location=
type=SOURCE
[./kfind.h]
dist=true
install=false
install_location=
type=HEADER
[./kfindpart.cpp]
dist=true
install=false
install_location=
type=SOURCE
[./kfindpart.desktop]
dist=true
install=false
install_location=
type=DATA
[./kfindpart.h]
dist=true
install=false
install_location=
type=HEADER
[./kfindpart.kdevprj]
dist=true
install=false
install_location=
type=DATA
[./kftabdlg.cpp]
dist=true
install=false
install_location=
type=SOURCE
[./kftabdlg.h]
dist=true
install=false
install_location=
type=HEADER
[./kquery.cpp]
dist=true
install=false
install_location=
type=SOURCE
[./kquery.h]
dist=true
install=false
install_location=
type=HEADER
[./version.h]
dist=true
install=false
install_location=
type=HEADER
[Config for BinMakefileAm]
addcxxflags=
bin_program=kfindpart
cxxflags=
ldadd=
ldflags=
[General]
AMChanged=false
author=eric
email=eric@darkstar.fr
kdevprj_version=1.3
lfv_open_groups=
makefiles=./Makefile.am,pics/Makefile.am,
project_name=kfindpart
project_type=normal_empty
sub_dir=
version=
version_control=CVS
workspace=1
[LFV Groups]
Desktop=*.desktop,
GNU=AUTHORS,COPYING,ChangeLog,INSTALL,README,TODO,NEWS,
Headers=*.h,*.hxx,*.hpp,*.H,
Others=*,
Sources=*.cpp,*.c,*.cc,*.C,*.cxx,*.ec,*.ecpp,*.lxx,*.l++,*.ll,*.l,
Translations=*.ts,*.po,
User Interface=*.ui,*.kdevdlg,*.rc,
groups=Headers,Sources,GNU,Translations,User Interface,Desktop,Others
[pics/Makefile.am]
files=pics/lo22-action-archive.png,pics/lo22-action-delete.png,pics/lo22-action-idea.png,pics/lo22-action-info.png,pics/lo22-action-openfile.png,pics/lo22-action-save.png,pics/lo22-action-search.png,
sub_dirs=
type=normal
[pics/lo22-action-archive.png]
dist=true
install=false
install_location=
type=DATA
[pics/lo22-action-delete.png]
dist=true
install=false
install_location=
type=DATA
[pics/lo22-action-idea.png]
dist=true
install=false
install_location=
type=DATA
[pics/lo22-action-info.png]
dist=true
install=false
install_location=
type=DATA
[pics/lo22-action-openfile.png]
dist=true
install=false
install_location=
type=DATA
[pics/lo22-action-save.png]
dist=true
install=false
install_location=
type=DATA
[pics/lo22-action-search.png]
dist=true
install=false
install_location=
type=DATA

35
kfind/kfindpart.kdevses Normal file
View file

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE KDevPrjSession ><KDevPrjSession>
<Mainframe MaximizeMode="0" />
<DocsAndViews NumberOfDocuments="10" >
<Doc0 CursorPosLine="93" Type="KWriteDoc" NumberOfViews="1" CursorPosCol="0" FileName="/home/eric/kdebase/konqueror/kfindpart/kftabdlg.h" >
<View0 Top="0" Width="779" Attach="0" Height="421" Left="0" Focus="0" Type="KWriteView" MinMaxMode="0" />
</Doc0>
<Doc1 CursorPosLine="210" Type="KWriteDoc" NumberOfViews="1" CursorPosCol="43" FileName="/home/eric/kdebase/konqueror/kfindpart/kftabdlg.cpp" >
<View0 Top="0" Width="94" Attach="0" Height="1" Left="0" Focus="0" Type="KWriteView" MinMaxMode="0" />
</Doc1>
<Doc2 CursorPosLine="101" Type="KWriteDoc" NumberOfViews="1" CursorPosCol="0" FileName="/home/eric/kdebase/konqueror/kfindpart/kfindpart.h" >
<View0 Top="0" Width="779" Attach="0" Height="421" Left="0" Focus="0" Type="KWriteView" MinMaxMode="0" />
</Doc2>
<Doc3 CursorPosLine="31" Type="KWriteDoc" NumberOfViews="1" CursorPosCol="0" FileName="/home/eric/kdebase/konqueror/kfindpart/kfindpart.cpp" >
<View0 Top="0" Width="779" Attach="0" Height="421" Left="0" Focus="0" Type="KWriteView" MinMaxMode="0" />
</Doc3>
<Doc4 CursorPosLine="43" Type="KWriteDoc" NumberOfViews="1" CursorPosCol="0" FileName="/home/eric/kdebase/konqueror/kfindpart/kfind.cpp" >
<View0 Top="0" Width="779" Attach="0" Height="421" Left="0" Focus="0" Type="KWriteView" MinMaxMode="0" />
</Doc4>
<Doc5 CursorPosLine="125" Type="KWriteDoc" NumberOfViews="1" CursorPosCol="74" FileName="/home/eric/kdebase/konqueror/kfindpart/kquery.cpp" >
<View0 Top="0" Width="779" Attach="0" Height="421" Left="0" Focus="0" Type="KWriteView" MinMaxMode="0" />
</Doc5>
<Doc6 CursorPosLine="265" Type="KWriteDoc" NumberOfViews="1" CursorPosCol="0" FileName="/home/eric/kdebase/libkonq/konq_dirpart.cc" >
<View0 Top="0" Width="779" Attach="0" Height="421" Left="0" Focus="0" Type="KWriteView" MinMaxMode="0" />
</Doc6>
<Doc7 CursorPosLine="243" Type="KWriteDoc" NumberOfViews="1" CursorPosCol="0" FileName="/home/eric/kdebase/libkonq/konq_dirpart.h" >
<View0 Top="0" Width="779" Attach="0" Height="421" Left="0" Focus="0" Type="KWriteView" MinMaxMode="0" />
</Doc7>
<Doc8 CursorPosLine="19" Type="KWriteDoc" NumberOfViews="1" CursorPosCol="0" FileName="/home/eric/kdebase/konqueror/kfindpart/kfind.h" >
<View0 Top="0" Width="779" Attach="0" Height="421" Left="0" Focus="1" Type="KWriteView" MinMaxMode="0" />
</Doc8>
<Doc9 Type="CDocBrowser" NumberOfViews="1" FileName="file:/usr/share/doc/HTML/en//kdecore/KLibFactory.html" >
<View Top="0" Width="779" Attach="0" Height="421" Left="0" Focus="0" Type="KHTMLView" MinMaxMode="0" />
</Doc9>
</DocsAndViews>
</KDevPrjSession>

576
kfind/kftabdlg.cpp Normal file
View file

@ -0,0 +1,576 @@
/***********************************************************************
*
* kftabdlg.cpp
*
**********************************************************************/
#include <qbuttongroup.h>
#include <qradiobutton.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qcheckbox.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kfiledialog.h>
#include "kquery.h"
#include <qpushbutton.h>
#include <kglobal.h>
#include "kftabdlg.moc"
// Static utility functions
static void save_pattern(QComboBox *, const QString &, const QString &);
#define SPECIAL_TYPES 7
class KSortedMimeTypeList : public QPtrList<KMimeType>
{
public:
KSortedMimeTypeList() { };
int compareItems(QPtrCollection::Item s1, QPtrCollection::Item s2)
{
KMimeType *item1 = (KMimeType *) s1;
KMimeType *item2 = (KMimeType *) s2;
if (item1->comment() > item2->comment()) return 1;
if (item1->comment() == item2->comment()) return 0;
return -1;
}
};
KfindTabWidget::KfindTabWidget(QWidget *parent, const char *name)
: QTabWidget( parent, name )
{
// This validator will be used for all numeric edit fields
KDigitValidator *digitV = new KDigitValidator(this);
// ************ Page One ************
pages[0] = new QWidget( this, "page1" );
nameBox = new QComboBox(TRUE, pages[0], "combo1");
QLabel * namedL = new QLabel(nameBox, i18n("&Named:"), pages[0], "named");
dirBox = new QComboBox(TRUE, pages[0], "combo2");
QLabel * lookinL = new QLabel(dirBox, i18n("&Look in:"), pages[0], "named");
subdirsCb = new QCheckBox(i18n("Include &subdirectories"), pages[0]);
caseSensCb = new QCheckBox(i18n("&Case sensitive search"), pages[0]);
browseB = new QPushButton(i18n("&Browse..."), pages[0]);
// Setup
subdirsCb->setChecked(true);
caseSensCb->setChecked(true);
nameBox->setDuplicatesEnabled(FALSE);
dirBox->setDuplicatesEnabled(FALSE);
nameBox->setInsertionPolicy(QComboBox::AtTop);
dirBox->setInsertionPolicy(QComboBox::AtTop);
// Layout
QGridLayout *grid = new QGridLayout( pages[0], 3, 3,
KDialog::marginHint(),
KDialog::spacingHint() );
QBoxLayout *subgrid = new QHBoxLayout( -1 , "subgrid" );
grid->addWidget( namedL, 0, 0 );
grid->addMultiCellWidget( nameBox, 0, 0, 1, 2 );
grid->addWidget( lookinL, 1, 0 );
grid->addWidget( dirBox, 1, 1 );
grid->addWidget( browseB, 1, 2);
grid->setColStretch(1,1);
grid->addMultiCellLayout( subgrid, 2, 2, 1, 2 );
subgrid->addWidget( subdirsCb );
subgrid->addSpacing( KDialog::spacingHint() );
subgrid->addWidget( caseSensCb);
subgrid->addStretch(1);
// Signals
connect( browseB, SIGNAL(clicked()),
this, SLOT(getDirectory()) );
addTab( pages[0], i18n(" Name/Location ") );
// ************ Page Two
pages[1] = new QWidget( this, "page2" );
findCreated = new QCheckBox(i18n("Find all files created or &modified:"), pages[1]);
bg = new QButtonGroup();
rb[0] = new QRadioButton(i18n("&between"), pages[1] );
rb[1] = new QRadioButton(i18n("during the previou&s"), pages[1] );
QLabel * andL = new QLabel(i18n("and"), pages[1], "and");
betweenType = new QComboBox(FALSE, pages[1], "comboBetweenType");
betweenType->insertItem(i18n("minute(s)"));
betweenType->insertItem(i18n("hour(s)"));
betweenType->insertItem(i18n("day(s)"));
betweenType->insertItem(i18n("month(s)"));
betweenType->insertItem(i18n("year(s)"));
betweenType->setCurrentItem(1);
fromDate = new KDateCombo(QDate(2000,1,1), pages[1], "fromDate");
toDate = new KDateCombo(pages[1], "toDate");
timeBox = new QSpinBox(1, 60, 1, pages[1], "timeBox");
rb[0]->setChecked(true);
// Setup
timeBox->setButtonSymbols(QSpinBox::PlusMinus);
bg->insert( rb[0] );
bg->insert( rb[1] );
// Layout
QGridLayout *grid1 = new QGridLayout( pages[1], 5, 4,
KDialog::marginHint(),
KDialog::spacingHint() );
grid1->addMultiCellWidget(findCreated, 0, 0, 0, 6 );
grid1->addColSpacing(0, KDialog::spacingHint());
grid1->addWidget(rb[0], 2, 1 );
grid1->addWidget(fromDate, 2, 2 );
grid1->addWidget(andL, 2, 3, AlignHCenter );
grid1->addWidget(toDate, 2, 4 );
grid1->addWidget(rb[1], 3, 1 );
grid1->addWidget(timeBox, 3, 2);
grid1->addWidget(betweenType, 3, 3 );
// Connect
connect( findCreated, SIGNAL(toggled(bool)), this, SLOT(fixLayout()) );
connect( bg, SIGNAL(clicked(int)), this, SLOT(fixLayout()) );
addTab( pages[1], i18n(" Date Range ") );
// ************ Page Three
pages[2] = new QWidget( this, "page3" );
typeBox =new QComboBox(FALSE, pages[2], "typeBox");
QLabel * typeL =new QLabel(typeBox, i18n("Of &type:"), pages[2], "type");
textEdit=new QLineEdit(pages[2], "textEdit" );
QLabel * textL =new QLabel(textEdit, i18n("&Containing Text:"), pages[2], "text");
caseContextCb =new QCheckBox(i18n("Case S&ensitive (content)"), pages[2]);
regexpContentCb =new QCheckBox(i18n("Use &Regular Expression Matching"), pages[2]);
sizeBox =new QComboBox(FALSE, pages[2], "sizeBox");
QLabel * sizeL =new QLabel(sizeBox,i18n("&Size is:"), pages[2],"size");
sizeEdit=new QSpinBox(1, INT_MAX, 1, pages[2], "sizeEdit" );
sizeUnitBox =new QComboBox(FALSE, pages[2], "sizeUnitBox");
// Setup
typeBox->insertItem(i18n("All Files and Directories"));
typeBox->insertItem(i18n("Files"));
typeBox->insertItem(i18n("Directories"));
typeBox->insertItem(i18n("Symbolic links"));
typeBox->insertItem(i18n("Special files (sockets, device files...)"));
typeBox->insertItem(i18n("Executable files"));
typeBox->insertItem(i18n("SUID executable files"));
initMimeTypes();
for ( KMimeType::List::ConstIterator it = m_types.begin();
it != m_types.end(); ++it )
{
KMimeType::Ptr typ = *it;
typeBox->insertItem(typ->comment());
}
sizeBox ->insertItem( i18n("(none)") );
sizeBox ->insertItem( i18n("At Least") );
sizeBox ->insertItem( i18n("At Most") );
sizeBox ->insertItem( i18n("Equal to") );
sizeUnitBox ->insertItem( "Bytes" );
sizeUnitBox ->insertItem( "Kb" );
sizeUnitBox ->insertItem( "Mb" );
sizeUnitBox ->setCurrentItem(1);
sizeEdit->setButtonSymbols(QSpinBox::PlusMinus);
int tmp = sizeEdit->fontMetrics().width(" 000000000 ");
sizeEdit->setMinimumSize(tmp, sizeEdit->sizeHint().height());
// Connect
connect( sizeBox, SIGNAL(highlighted(int)), this, SLOT(slotSizeBoxChanged(int)));
// Layout
tmp = sizeEdit->fontMetrics().width(" 00000 ");
sizeEdit->setMinimumSize(tmp, sizeEdit->sizeHint().height());
QGridLayout *grid2 = new QGridLayout( pages[2], 4, 6,
KDialog::marginHint(),
KDialog::spacingHint() );
grid2->addWidget( typeL, 0, 0 );
grid2->addWidget( textL, 1, 0 );
grid2->addWidget( sizeL, 2, 0 );
grid2->addMultiCellWidget( typeBox, 0, 0, 1, 6 );
grid2->addMultiCellWidget( textEdit, 1, 1, 1, 4/*6*/ );
grid2->addWidget( caseContextCb, 1, 5 );
grid2->addWidget( regexpContentCb, 2, 5);
grid2->addWidget( sizeBox, 2, 1 );
grid2->addWidget( sizeEdit, 2, 2 );
grid2->addWidget( sizeUnitBox, 2, 3 );
grid2->addColSpacing(4, KDialog::spacingHint());
grid2->setColStretch(6,1);
addTab( pages[2], i18n(" Advanced ") );
fixLayout();
loadHistory();
}
KfindTabWidget::~KfindTabWidget()
{
delete pages[0];
delete pages[1];
delete pages[2];
}
void KfindTabWidget::setURL( const KURL & url )
{
KConfig *conf = KGlobal::config();
conf->setGroup("History");
m_url = url;
QStringList sl = conf->readListEntry("Directories", ',');
if(!sl.isEmpty()) {
dirBox->insertStringList(sl);
// If the _searchPath already exists in the list we do not
// want to add it again
int indx = sl.findIndex(m_url.url());
if(indx == -1)
dirBox->insertItem(m_url.url(), 0); // make it the first one
else
dirBox->setCurrentItem(indx);
}
else {
QDir m_dir("/lib");
dirBox ->insertItem( m_url.url() );
dirBox ->insertItem( "file:/" );
dirBox ->insertItem( "file:/usr" );
if (m_dir.exists())
dirBox ->insertItem( "file:/lib" );
dirBox ->insertItem( "file:/home" );
dirBox ->insertItem( "file:/etc" );
dirBox ->insertItem( "file:/var" );
dirBox ->insertItem( "file:/mnt" );
}
}
void
KfindTabWidget::initMimeTypes()
{
KMimeType::List tmp = KMimeType::allMimeTypes();
KSortedMimeTypeList sortedList;
for ( KMimeType::List::ConstIterator it = tmp.begin();
it != tmp.end(); ++it )
{
KMimeType * type = *it;
sortedList.append(type);
}
sortedList.sort();
for ( KMimeType *type = sortedList.first(); type; type = sortedList.next())
{
m_types.append(type);
}
}
void KfindTabWidget::saveHistory()
{
save_pattern(nameBox, "History", "Patterns");
save_pattern(dirBox, "History", "Directories");
}
void KfindTabWidget::loadHistory()
{
// Load pattern history
KConfig *conf = KGlobal::config();
conf->setGroup("History");
QStringList sl = conf->readListEntry("Patterns", ',');
if(!sl.isEmpty())
nameBox->insertStringList(sl);
else
nameBox->insertItem("*");
}
void KfindTabWidget::slotSizeBoxChanged(int index)
{
sizeEdit->setEnabled((bool)(index != 0));
sizeUnitBox->setEnabled((bool)(index != 0));
}
void KfindTabWidget::setDefaults()
{
fromDate ->setDate(QDate(2000,1,1));
toDate ->setDate(QDate::currentDate());
timeBox->setValue(1);
betweenType->setCurrentItem(1);
typeBox ->setCurrentItem(0);
sizeBox ->setCurrentItem(0);
sizeUnitBox ->setCurrentItem(1);
sizeEdit->setValue(1);
}
/*
Checks if dates are correct and popups a error box
if they are not.
*/
bool KfindTabWidget::isDateValid()
{
// All files
if ( !findCreated->isChecked() ) return TRUE;
if (rb[1]->isChecked())
{
if (timeBox->value() > 0 ) return TRUE;
KMessageBox::sorry(this, i18n("Can't search in a period which doesn't last a single minute."));
return FALSE;
}
// If we can not parse either of the dates or
// "from" date is bigger than "to" date return FALSE.
QDate hi1, hi2;
QString str;
if ( ! fromDate->getDate(&hi1).isValid() ||
! toDate->getDate(&hi2).isValid() )
str = i18n("The date is not valid!");
else if ( hi1 > hi2 )
str = i18n("Invalid date range!");
else if ( QDate::currentDate() < hi1 )
str = i18n("Well, how can I search dates in the future ?");
if (!str.isNull()) {
KMessageBox::sorry(0, str);
return FALSE;
}
return TRUE;
}
void KfindTabWidget::setQuery(KQuery *query)
{
int size;
// only start if we have valid dates
if (!isDateValid()) return;
query->setPath(KURL(dirBox->currentText()));
query->setRegExp(QRegExp(nameBox->currentText(), caseSensCb->isChecked(), true));
query->setRecursive(subdirsCb->isChecked());
switch (sizeUnitBox->currentItem())
{
case 0:
size = 1; //one byte
break;
case 2:
size = 1048576; //1M
break;
case 1:
default:
size=1024; //1k
break;
}
size = sizeEdit->value() * size;
if (size < 0) // overflow
if (KMessageBox::warningYesNo(this, i18n("Size is too big... would you set max size value ?"), i18n("Sorry"))
== KMessageBox::Yes)
{
sizeEdit->setValue(INT_MAX);
sizeUnitBox->setCurrentItem(0);
size = INT_MAX;
}
else
return;
switch (sizeBox->currentItem())
{
case 1:
query->setSizeRange(sizeEdit->text().toInt() * 1024, -1);
break;
case 2:
query->setSizeRange(-1, sizeEdit->text().toInt() * 1024);
break;
default:
query->setSizeRange(-1, -1);
}
// dates
QDateTime epoch;
epoch.setTime_t(0);
// Add date predicate
if (findCreated->isChecked()) { // Modified
if (rb[0]->isChecked()) { // Between dates
QDate q1, q2;
fromDate->getDate(&q1);
toDate->getDate(&q2);
// do not generate negative numbers .. find doesn't handle that
time_t time1 = epoch.secsTo(q1);
time_t time2 = epoch.secsTo(q2);
query->setTimeRange(time1, time2);
}
else
{
time_t cur = time(NULL);
time_t minutes = cur;
switch (betweenType->currentItem())
{
case 0: // minutes
minutes = timeBox->value();
break;
case 1: // hours
minutes = 60 * timeBox->value();
break;
case 2: // days
minutes = 60 * 24 * timeBox->value();
break;
case 3: // months
minutes = 60 * 24 * (time_t)(timeBox->value() * 30.41667);
break;
case 4: // years
minutes = 12 * 60 * 24 * (time_t)(timeBox->value() * 30.41667);
break;
}
query->setTimeRange(cur - minutes * 60, 0);
}
}
else
query->setTimeRange(0, 0);
query->setFileType(typeBox->currentItem());
int id = typeBox->currentItem()-7;
if ((id >= 0) && (id < (int) m_types.count()))
{
query->setMimeType( m_types[id]->name() );
}
else
{
query->setMimeType( QString::null );
}
query->setContext(textEdit->text(), caseContextCb->isChecked(), regexpContentCb->isChecked());
}
QString KfindTabWidget::date2String(const QDate & date) {
return(KGlobal::locale()->formatDate(date, true));
}
QDate &KfindTabWidget::string2Date(const QString & str, QDate *qd) {
return *qd = KGlobal::locale()->readDate(str);
}
void KfindTabWidget::getDirectory()
{
QString result =
KFileDialog::getExistingDirectory( dirBox->text(dirBox->currentItem()),
this );
if (!result.isEmpty())
{
for (int i = 0; i < dirBox->count(); i++)
if (result == dirBox->text(i)) {
dirBox->setCurrentItem(i);
return;
}
dirBox->insertItem(result, 0);
dirBox->setCurrentItem(0);
}
}
void KfindTabWidget::beginSearch()
{
saveHistory();
setEnabled( FALSE );
}
void KfindTabWidget::endSearch()
{
setEnabled( TRUE );
}
/*
Disables/enables all edit fields depending on their
respective check buttons.
*/
void KfindTabWidget::fixLayout()
{
int i;
// If "All files" is checked - disable all edits
// and second radio group on page two
if(! findCreated->isChecked()) {
fromDate->setEnabled(FALSE);
toDate->setEnabled(FALSE);
timeBox->setEnabled(FALSE);
for(i=0; i<2; i++)
rb[i]->setEnabled(FALSE);
betweenType->setEnabled(FALSE);
}
else {
for(i=0; i<2; i++)
rb[i]->setEnabled(TRUE);
fromDate->setEnabled(rb[0]->isChecked());
toDate->setEnabled(rb[0]->isChecked());
timeBox->setEnabled(rb[1]->isChecked());
betweenType->setEnabled(rb[1]->isChecked());
}
// Size box on page three
sizeEdit->setEnabled(sizeBox->currentItem() != 0);
sizeUnitBox->setEnabled(sizeBox->currentItem() != 0);
}
/**
Digit validator. Allows only digits to be typed.
**/
KDigitValidator::KDigitValidator( QWidget * parent, const char *name )
: QValidator( parent, name )
{
r = new QRegExp("^[0-9]*$");
}
KDigitValidator::~KDigitValidator()
{}
QValidator::State KDigitValidator::validate( QString & input, int & ) const
{
if (r->search(input) < 0) {
// Beep on user if he enters non-digit
QApplication::beep();
return QValidator::Invalid;
}
else
return QValidator::Acceptable;
}
//*******************************************************
// Static utility functions
//*******************************************************
static void save_pattern(QComboBox *obj,
const QString & group, const QString & entry)
{
// QComboBox allows insertion of items more than specified by
// maxCount() (QT bug?). This API call will truncate list if needed.
obj->setMaxCount(15);
QStringList sl;
for (int i = 0; i < obj->count(); i++)
sl.append(obj->text(i));
KConfig *conf = KGlobal::config();
conf->setGroup(group);
conf->writeEntry(entry, sl, ',');
}

118
kfind/kftabdlg.h Normal file
View file

@ -0,0 +1,118 @@
/***********************************************************************
*
* kftabdlg.h
*
***********************************************************************/
#ifndef KFTABDLG_H
#define KFTABDLG_H
#include <qtabwidget.h>
#include <qcombobox.h>
#include <qspinbox.h>
#include <qvalidator.h> // for KDigitValidator
#include <kurl.h>
#include <kmimetype.h>
#include "kdatecombo.h"
class QButtonGroup;
class QPushButton;
class QRadioButton;
class QCheckBox;
class QLineEdit;
class QString;
class QDate;
class QRegExp;
class KfDirDialog;
class KfindTabWidget: public QTabWidget
{
Q_OBJECT
public:
KfindTabWidget(QWidget * parent = 0, const char *name=0);
virtual ~KfindTabWidget();
void initMimeTypes();
void setQuery(class KQuery * query);
void setDefaults();
void beginSearch();
void endSearch();
void loadHistory();
void saveHistory();
void setURL( const KURL & url );
public slots:
void setFocus() { nameBox->setFocus(); }
private slots:
void getDirectory();
void fixLayout();
void slotSizeBoxChanged(int);
signals:
protected:
public:
QComboBox *nameBox;
QComboBox *dirBox;
// for first page
QCheckBox *subdirsCb;
// for third page
QComboBox *typeBox;
QLineEdit * textEdit;
QCheckBox *caseSensCb;
private:
bool isDateValid();
QString date2String(const QDate &);
QDate &string2Date(const QString &, QDate * );
QWidget *pages[3];
//1st page
QPushButton *browseB;
KfDirDialog *dirselector;
//2nd page
QCheckBox *findCreated;
QComboBox *betweenType;
QButtonGroup *bg;
QRadioButton *rb[2];
KDateCombo * fromDate;
KDateCombo * toDate;
QSpinBox *timeBox;
//3rd page
QComboBox *sizeBox;
QComboBox *sizeUnitBox;
QSpinBox *sizeEdit;
QCheckBox *caseContextCb;
QCheckBox *regexpContentCb;
KURL m_url;
KMimeType::List m_types;
};
class KDigitValidator : public QValidator
{
Q_OBJECT
public:
KDigitValidator(QWidget * parent, const char *name = 0 );
~KDigitValidator();
QValidator::State validate(QString & input, int &) const;
private:
QRegExp *r;
};
#endif

427
kfind/kfwin.cpp Normal file
View file

@ -0,0 +1,427 @@
/***********************************************************************
*
* Kfwin.cpp
*
**********************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <pwd.h>
#include <grp.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <time.h>
#include <qtextstream.h>
#include <qfileinfo.h>
#include <qdir.h>
#include <qclipboard.h>
#include <qpixmap.h>
#include <qdragobject.h>
#include <kfiledialog.h>
#include <klocale.h>
#include <kapp.h>
#include <krun.h>
#include <kprocess.h>
#include <kpropsdlg.h>
#include <kstddirs.h>
#include <kmessagebox.h>
#include <kmimetype.h>
#include <kglobal.h>
#include <kopenwith.h>
#include <kpopupmenu.h>
#include <kio/netaccess.h>
#include <kurl.h>
#include <kurldrag.h>
#include <qptrlist.h>
#include "kfwin.h"
#include "kfwin.moc"
template class QPtrList<KfFileLVI>;
// Permission strings
static const char* perm[4] = {
I18N_NOOP( "Read-write" ),
I18N_NOOP( "Read-only" ),
I18N_NOOP( "Write-only" ),
I18N_NOOP( "Inaccessible" ) };
#define RW 0
#define RO 1
#define WO 2
#define NA 3
KfFileLVI::KfFileLVI(KfindWindow* lv, const KFileItem &item, const QString& matchingLine)
: QListViewItem(lv),
fileitem(item)
{
fileInfo = new QFileInfo(item.url().path());
QString size = KGlobal::locale()->formatNumber(item.size(), 0);
QDateTime dt;
dt.setTime_t(item.time(KIO::UDS_MODIFICATION_TIME));
QString date = KGlobal::locale()->formatDateTime(dt);
int perm_index;
if(fileInfo->isReadable())
perm_index = fileInfo->isWritable() ? RW : RO;
else
perm_index = fileInfo->isWritable() ? WO : NA;
// Fill the item with data
setText(0, item.url().fileName(false));
setText(1, lv->reducedDir(item.url().directory(false)));
setText(2, size);
setText(3, date);
setText(4, i18n(perm[perm_index]));
setText(5, matchingLine);
// put the icon into the leftmost column
setPixmap(0, item.pixmap(16));
}
KfFileLVI::~KfFileLVI()
{
delete fileInfo;
}
QString KfFileLVI::key(int column, bool) const
{
switch (column) {
case 2:
// Returns date in bytes. Used for sorting
return QString().sprintf("%10d", fileInfo->size());
case 3:
// Returns time in secs from 1/1/1970. Used for sorting
return QString().sprintf("%10ld", fileitem.time(KIO::UDS_MODIFICATION_TIME));
}
return text(column);
}
KfindWindow::KfindWindow( QWidget *parent, const char *name )
: KListView( parent, name )
,m_baseDir("")
,m_menu(0)
{
setSelectionMode( QListView::Extended );
setShowSortIndicator( TRUE );
addColumn(i18n("Name"));
addColumn(i18n("In subdirectory"));
addColumn(i18n("Size"));
setColumnAlignment(2, AlignRight);
addColumn(i18n("Modified"));
setColumnAlignment(3, AlignRight);
addColumn(i18n("Permissions"));
setColumnAlignment(4, AlignRight);
addColumn(i18n("First matching line"));
setColumnAlignment(5, AlignLeft);
// Disable autoresize for all columns
// Resizing is done by resetColumns() function
for (int i = 0; i < 6; i++)
setColumnWidthMode(i, Manual);
resetColumns(TRUE);
connect( this, SIGNAL(selectionChanged()),
this, SLOT( selectionHasChanged() ));
connect(this, SIGNAL(contextMenu(KListView *, QListViewItem*,const QPoint&)),
this, SLOT(slotContextMenu(KListView *,QListViewItem*,const QPoint&)));
connect(this, SIGNAL(executed(QListViewItem*)),
this, SLOT(slotExecute(QListViewItem*)));
setDragEnabled(true);
}
QString KfindWindow::reducedDir(const QString& fullDir)
{
if (fullDir.find(m_baseDir)==0)
{
QString tmp=fullDir.mid(m_baseDir.length());
return tmp;
};
return fullDir;
};
void KfindWindow::beginSearch(const KURL& baseUrl)
{
m_baseDir=baseUrl.path(+1);
haveSelection = false;
clear();
}
void KfindWindow::endSearch()
{
}
void KfindWindow::insertItem(const KFileItem &item, const QString& matchingLine)
{
new KfFileLVI(this, item, matchingLine);
}
// copy to clipboard aka X11 selection
void KfindWindow::copySelection()
{
QDragObject *drag_obj = dragObject();
if (drag_obj)
{
QClipboard *cb = kapp->clipboard();
cb->setData(drag_obj);
}
}
void KfindWindow::saveResults()
{
QListViewItem *item;
KFileDialog *dlg = new KFileDialog(QString::null, QString::null, this,
"filedialog", true);
dlg->setCaption(i18n("Save Results As"));
KMimeType::List list;
list.append(KMimeType::mimeType("text/plain"));
list.append(KMimeType::mimeType("text/html"));
dlg->setFilterMimeType(i18n("Save as:"), list, KMimeType::mimeType("text/plain"));
dlg->exec();
KURL u = dlg->selectedURL();
KMimeType::Ptr mimeType = dlg->currentFilterMimeType();
delete dlg;
if (u.isMalformed() || !u.isLocalFile())
return;
QString filename = u.path();
QFile file(filename);
if ( !file.open(IO_WriteOnly) )
KMessageBox::error(parentWidget(),
i18n("It wasn't possible to save results!"));
else {
QTextStream stream( &file );
stream.setEncoding( QTextStream::Locale );
if ( mimeType->name() == "text/html") {
stream << QString::fromLatin1("<HTML><HEAD>\n"
"<!DOCTYPE %1>\n"
"<TITLE>%2</TITLE></HEAD>\n"
"<BODY><H1>%3</H1>"
"<DL><p>\n")
.arg(i18n("KFind Results File"))
.arg(i18n("KFind Results File"))
.arg(i18n("KFind Results File"));
item = firstChild();
while(item != NULL)
{
QString path=((KfFileLVI*)item)->fileitem.url().url();
QString pretty=((KfFileLVI*)item)->fileitem.url().prettyURL();
stream << QString::fromLatin1("<DT><A HREF=\"%1\">%2</A>\n")
.arg(path).arg(pretty);
item = item->nextSibling();
}
stream << QString::fromLatin1("</DL><P></BODY></HTML>\n");
}
else {
item = firstChild();
while(item != NULL)
{
QString path=((KfFileLVI*)item)->fileitem.url().url();
stream << path << endl;
item = item->nextSibling();
}
}
file.close();
KMessageBox::information(parentWidget(),
i18n("Results were saved to file\n")+
filename);
}
}
// This function is called when selection is changed (both selected/deselected)
// It notifies the parent about selection status and enables/disables menubar
void KfindWindow::selectionHasChanged()
{
emit resultSelected(true);
QListViewItem *item = firstChild();
while(item != 0L)
{
if(isSelected(item)) {
emit resultSelected( true );
haveSelection = true;
return;
}
item = item->nextSibling();
}
haveSelection = false;
emit resultSelected(false);
}
void KfindWindow::deleteFiles()
{
QString tmp = i18n("Do you really want to delete selected file(s)?");
if (KMessageBox::questionYesNo(parentWidget(), tmp) == KMessageBox::No)
return;
// Iterate on all selected elements
QPtrList<QListViewItem> selected = selectedItems();
for ( uint i = 0; i < selected.count(); i++ ) {
KfFileLVI *item = (KfFileLVI *) selected.at(i);
KFileItem file = item->fileitem;
KIO::NetAccess::del(file.url());
}
selected.setAutoDelete(true);
}
void KfindWindow::fileProperties()
{
// This dialog must be modal because it parent dialog is modal as well.
// Non-modal property dialog will hide behind the main window
(void) new KPropertiesDialog( &((KfFileLVI *)currentItem())->fileitem, this,
"propDialog", true);
}
void KfindWindow::openFolder()
{
KFileItem fileitem = ((KfFileLVI *)currentItem())->fileitem;
KURL url = fileitem.url();
url.setFileName(QString::null);
(void) new KRun(url);
}
void KfindWindow::openBinding()
{
((KfFileLVI*)currentItem())->fileitem.run();
}
void KfindWindow::slotExecute(QListViewItem* item)
{
if (item==0)
return;
((KfFileLVI*)item)->fileitem.run();
}
// Resizes KListView to occupy all visible space
void KfindWindow::resizeEvent(QResizeEvent *e)
{
KListView::resizeEvent(e);
resetColumns(FALSE);
clipper()->repaint();
}
QDragObject * KfindWindow::dragObject() const
{
KURL::List uris;
QPtrList<QListViewItem> selected = selectedItems();
// create a list of URIs from selection
for ( uint i = 0; i < selected.count(); i++ )
{
KfFileLVI *item = (KfFileLVI *) selected.at( i );
if (item)
{
uris.append( item->fileitem.url() );
}
}
if ( uris.count() <= 0 )
return 0;
QUriDrag *ud = KURLDrag::newDrag( uris, (QWidget *) this, "kfind uridrag" );
const QPixmap *pix = currentItem()->pixmap(0);
if ( pix && !pix->isNull() )
ud->setPixmap( *pix );
return ud;
}
void KfindWindow::resetColumns(bool init)
{
QFontMetrics fm = fontMetrics();
if (init)
{
setColumnWidth(2, QMAX(fm.width(columnText(2)), fm.width("0000000")) + 15);
QString sampleDate =
KGlobal::locale()->formatDateTime(QDateTime::currentDateTime());
setColumnWidth(3, QMAX(fm.width(columnText(3)), fm.width(sampleDate)) + 15);
setColumnWidth(4, QMAX(fm.width(columnText(4)), fm.width(i18n(perm[RO]))) + 15);
setColumnWidth(5, QMAX(fm.width(columnText(5)), fm.width("some text")) + 15);
}
int free_space = visibleWidth() -
columnWidth(2) - columnWidth(3) - columnWidth(4) - columnWidth(5);
// int name_w = QMIN((int)(free_space*0.5), 150);
// int dir_w = free_space - name_w;
int name_w = QMAX((int)(free_space*0.5), fm.width("some long filename"));
int dir_w = name_w;
setColumnWidth(0, name_w);
setColumnWidth(1, dir_w);
}
void KfindWindow::slotContextMenu(KListView *,QListViewItem *item,const QPoint&p)
{
if (!item) return;
int count = selectedItems().count();
if (count == 0)
{
return;
};
if (m_menu==0)
m_menu = new KPopupMenu(this);
else
m_menu->clear();
if (count == 1)
{
//menu = new KPopupMenu(item->text(0), this);
m_menu->insertTitle(item->text(0));
m_menu->insertItem(i18n("Copy"), this, SLOT(copySelection()));
m_menu->insertItem(i18n("Delete"), this, SLOT(deleteFiles()));
m_menu->insertItem(i18n("Open Directory"), this, SLOT(openFolder()));
m_menu->insertItem(i18n("Open With..."), this, SLOT(slotOpenWith()));
m_menu->insertItem(i18n("Open"), this, SLOT(openBinding()));
m_menu->insertSeparator();
m_menu->insertItem(i18n("Properties"), this, SLOT(fileProperties()));
}
else
{
m_menu->insertTitle(i18n("Selected Files"));
m_menu->insertItem(i18n("Copy"), this, SLOT(copySelection()));
m_menu->insertItem(i18n("Delete"), this, SLOT(deleteFiles()));
}
m_menu->popup(p, 1);
}
void KfindWindow::slotOpenWith()
{
KOpenWithHandler::getOpenWithHandler()->displayOpenWithDialog( KURL::split(((KfFileLVI*)currentItem())->fileitem.url()) );
}

75
kfind/kfwin.h Normal file
View file

@ -0,0 +1,75 @@
/***********************************************************************
*
* Kfwin.h
*
***********************************************************************/
#ifndef KFWIN_H
#define KFWIN_H
#include <klistview.h>
#include <kfileitem.h>
#include <kurl.h>
class KfArchiver;
class QPixmap;
class QFileInfo;
class KPopupMenu;
class KfindWindow;
class KfFileLVI : public QListViewItem
{
public:
KfFileLVI(KfindWindow* lv, const KFileItem &item,const QString& matchingLine);
~KfFileLVI();
QString key(int column, bool) const;
QFileInfo *fileInfo;
KFileItem fileitem;
};
class KfindWindow: public KListView
{
Q_OBJECT
public:
KfindWindow( QWidget * parent = 0, const char * name = 0 );
void beginSearch(const KURL& baseUrl);
void endSearch();
void insertItem(const KFileItem &item, const QString& matchingLine);
QString reducedDir(const QString& fullDir);
public slots:
void copySelection();
void slotContextMenu(KListView *,QListViewItem *item,const QPoint&p);
private slots:
void deleteFiles();
void fileProperties();
void openFolder();
void saveResults();
void openBinding();
void selectionHasChanged();
void slotExecute(QListViewItem*);
void slotOpenWith();
protected:
virtual void resizeEvent(QResizeEvent *e);
virtual QDragObject *dragObject() const;
signals:
void resultSelected(bool);
private:
QString m_baseDir;
KPopupMenu *m_menu;
bool haveSelection;
bool m_pressed;
void resetColumns(bool init);
};
#endif

213
kfind/kquery.cpp Normal file
View file

@ -0,0 +1,213 @@
#include <stdlib.h>
#include <qfile.h>
#include <kfileitem.h>
#include "kquery.moc"
KQuery::KQuery(QObject *parent, const char * name)
: QObject(parent, name),
m_minsize(-1), m_maxsize(-1),
m_timeFrom(0), m_timeTo(0),
job(0)
{
}
KQuery::~KQuery()
{
}
void KQuery::kill()
{
if (job)
job->kill(false);
}
void KQuery::start()
{
if (m_recursive)
job = KIO::listRecursive( m_url, false );
else
job = KIO::listDir( m_url, false );
connect(job, SIGNAL(entries(KIO::Job *, const KIO::UDSEntryList &)),
SLOT(slotListEntries(KIO::Job *, const KIO::UDSEntryList &)));
connect(job, SIGNAL(result(KIO::Job *)), SLOT(slotResult(KIO::Job *)));
connect(job, SIGNAL(canceled(KIO::Job *)), SLOT(slotCanceled(KIO::Job *)));
}
void KQuery::slotResult( KIO::Job * _job )
{
if (job != _job) return;
job = 0;
emit result(_job->error());
}
void KQuery::slotCanceled( KIO::Job * _job )
{
if (job != _job) return;
job = 0;
emit result(KIO::ERR_USER_CANCELED);
}
void KQuery::slotListEntries( KIO::Job *, const KIO::UDSEntryList & list)
{
KIO::UDSEntryListConstIterator it = list.begin();
KIO::UDSEntryListConstIterator end = list.end();
for (; it != end; ++it)
{
KFileItem * file = new KFileItem(*it, m_url, true, true);
// we don't want this
if ( file->name() == "." || file->name() == ".." )
continue;
if ( !m_regexp.isEmpty() &&
m_regexp.search( file->url().fileName( true ) ) == -1 )
continue;
// make sure the files are in the correct range
if ( ( m_minsize >= 0 && file->size() < m_minsize ) ||
( m_maxsize >= 0 && file->size() > m_maxsize ) )
continue;
// make sure it's in the correct date range
// what about 0 times?
if ( m_timeFrom && m_timeFrom > file->time(KIO::UDS_MODIFICATION_TIME) )
continue;
if ( m_timeTo && m_timeTo < file->time(KIO::UDS_MODIFICATION_TIME) )
continue;
// file type
switch (m_filetype)
{
case 0:
break;
case 1: // plain file
if ( !S_ISREG( file->mode() ) )
continue;
break;
case 2:
if ( !file->isDir() )
continue;
break;
case 3:
if ( !file->isLink() )
continue;
break;
case 4:
if ( !S_ISCHR ( file->mode() ) && !S_ISBLK ( file->mode() ) &&
!S_ISFIFO( file->mode() ) && !S_ISSOCK( file->mode() ) )
continue;
break;
case 5: // binary
if ( (file->permissions() & 0111) != 0111) // fixme -- and not dir?
continue;
break;
case 6: // suid
if ( (file->permissions() & 04000) != 04000 ) // fixme
continue;
break;
default:
if (!m_mimetype.isEmpty() && m_mimetype != file->mimetype())
continue;
}
// match contents...
if (!m_context.isEmpty())
{
bool found = false;
// FIXME: doesn't work with non local files
QString filename = file->url().path();
if(filename.startsWith("/dev/")) //TEST: Perhaps we can search in /dev...
continue;
QFile qf(filename);
qf.open(IO_ReadOnly);
QTextStream stream(&qf);
stream.setEncoding(QTextStream::Locale);
while ( ! stream.atEnd() )
{
QString str = stream.readLine();
if (str.isNull()) break;
if (m_regexpForContent)
{
if (m_contentRegexp.search(str)>=0)
{
found = true;
break;
}
}
else
{
if (str.find(m_context, 0, m_casesensitive) != -1)
{
found = true;
break;
}
};
// kapp->processEvents();
}
if (!found)
continue;
}
emit addFile(file);
}
}
void KQuery::setContext(const QString & context, bool casesensitive, bool useRegexp)
{
m_context = context;
m_casesensitive = casesensitive;
m_regexpForContent=useRegexp;
m_contentRegexp.setWildcard(!m_regexpForContent);
m_contentRegexp.setCaseSensitive(casesensitive);
if (m_regexpForContent)
m_contentRegexp.setPattern(m_context);
}
void KQuery::setMimeType(const QString &mimetype)
{
m_mimetype = mimetype;
}
void KQuery::setFileType(int filetype)
{
m_filetype = filetype;
}
void KQuery::setSizeRange(int min, int max)
{
m_minsize = min;
m_maxsize = max;
}
void KQuery::setTimeRange(time_t from, time_t to)
{
m_timeFrom = from;
m_timeTo = to;
}
void KQuery::setRegExp(const QRegExp &regexp)
{
m_regexp = regexp;
}
void KQuery::setRecursive(bool recursive)
{
m_recursive = recursive;
}
void KQuery::setPath(const KURL &url)
{
m_url = url;
}

61
kfind/kquery.h Normal file
View file

@ -0,0 +1,61 @@
#ifndef KQUERY_H
#define KQUERY_H
#include <time.h>
#include <qobject.h>
#include <qregexp.h>
#include <kio/job.h>
#include <kurl.h>
class KFileItem;
class KQuery : public QObject
{
Q_OBJECT
public:
KQuery(QObject *parent = 0, const char * name = 0);
~KQuery();
void setSizeRange( int min, int max );
void setTimeRange( time_t from, time_t to );
void setRegExp( const QRegExp &regexp );
void setRecursive( bool recursive );
void setPath(const KURL & url );
void setFileType( int filetype );
void setMimeType( const QString & mimetype );
void setContext( const QString & context, bool casesensitive, bool useRegexp );
void start();
void kill();
protected slots:
void slotListEntries(KIO::Job *, const KIO::UDSEntryList &);
void slotResult(KIO::Job *);
void slotCanceled(KIO::Job *);
signals:
void addFile(const KFileItem *filename);
void result(int);
private:
int m_filetype;
int m_minsize;
int m_maxsize;
KURL m_url;
time_t m_timeFrom;
time_t m_timeTo;
QRegExp m_regexp;
bool m_recursive;
QString m_mimetype;
QString m_context;
bool m_casesensitive;
bool m_regexpForContent;
QRegExp m_contentRegexp;
KIO::ListJob *job;
};
#endif

62
kfind/main.cpp Normal file
View file

@ -0,0 +1,62 @@
#include <qdir.h>
#include <qfile.h>
#include <kapp.h>
#include <klocale.h>
#include <kcmdlineargs.h>
#include <kaboutdata.h>
#include "kfinddlg.h"
#include "version.h"
static const char *description =
I18N_NOOP("KDE File find utility.");
static KCmdLineOptions options[] =
{
{ "+[searchpath]", I18N_NOOP("Path(s) to search."), 0 },
{ 0,0,0 }
};
int main( int argc, char ** argv )
{
KAboutData aboutData( "kfind", I18N_NOOP("KFind"),
VERSION, description, KAboutData::License_GPL,
"(c) 1998-2001, The KDE Developers");
aboutData.addAuthor("Eric Coquelle", I18N_NOOP("Developer & Current Maintainer"), "coquelle@caramail.com");
aboutData.addAuthor("Beppe Grimaldi", I18N_NOOP("UI Design & more search options"), "grimalkin@ciaoweb.it");
aboutData.addAuthor("Mark W. Webb", I18N_NOOP("Developer"), "markwebb@adelphia.net");
aboutData.addAuthor("Martin Hartig");
aboutData.addAuthor("Stephan Kulow", 0, "coolo@kde.org");
aboutData.addAuthor("Mario Weilguni",0, "mweilguni@sime.com");
aboutData.addAuthor("Alex Zepeda",0, "jazepeda@pacbell.net");
aboutData.addAuthor("Miroslav Flídr",0, "flidr@kky.zcu.cz");
aboutData.addAuthor("Harri Porten",0, "porten@kde.org");
aboutData.addAuthor("Dima Rogozin",0, "dima@mercury.co.il");
aboutData.addAuthor("Carsten Pfeiffer",0, "pfeiffer@kde.org");
aboutData.addAuthor("Hans Petter Bieker", 0, "bieker@kde.org");
aboutData.addAuthor("Waldo Bastian", I18N_NOOP("UI Design"), "bastian@kde.org");
KCmdLineArgs::init( argc, argv, &aboutData );
KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
KApplication app;
KCmdLineArgs *args= KCmdLineArgs::parsedArgs();
KURL url;
if (args->count() > 0)
url = args->url(0);
if (url.isEmpty())
url = QDir::currentDirPath();
if (url.isEmpty())
url = QDir::homeDirPath();
args->clear();
KfindDlg kfinddlg(url, 0, "dialog");
return kfinddlg.exec();
}

2
kfind/pics/Makefile.am Normal file
View file

@ -0,0 +1,2 @@
datadir = $(kde_datadir)/kfindpart/icons
data_ICON = AUTO

Binary file not shown.

After

Width:  |  Height:  |  Size: 508 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 473 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 407 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 360 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 B

1
kfind/version.h Normal file
View file

@ -0,0 +1 @@
#define VERSION "2.0"