mirror of
https://invent.kde.org/system/dolphin
synced 2024-11-05 18:47:12 +00:00
Start magor clean up of kfind.
- use layout mechanism whereevr possible - port to KTMainWindow instead of TopLevelwidget - port to QTabWidget instead of QTabDialog - pressing enter now starts search Work is in progress... svn path=/trunk/kdebase/kfind/; revision=23975
This commit is contained in:
parent
ae7ba72811
commit
95b4643688
8 changed files with 413 additions and 572 deletions
|
@ -21,6 +21,7 @@
|
|||
#include <qstring.h>
|
||||
#include <qdir.h>
|
||||
#include <qkeycode.h>
|
||||
#include <qlayout.h>
|
||||
|
||||
#include <kmsgbox.h>
|
||||
#include <kprocess.h>
|
||||
|
@ -40,13 +41,20 @@ Kfind::Kfind( QWidget *parent, const char *name, const char *searchPath )
|
|||
// init IO buffer
|
||||
iBuffer = 0;
|
||||
|
||||
//create tabdialog
|
||||
tabDialog = new KfindTabDialog(this,"dialog",searchPath);
|
||||
QVBoxLayout *vBox = new QVBoxLayout(this);
|
||||
|
||||
//create tabwidget
|
||||
tabWidget = new KfindTabWidget(this,"dialog",searchPath);
|
||||
|
||||
//prepare window for find results
|
||||
win = new KfindWindow(this,"window");
|
||||
win->hide(); //and hide it firstly
|
||||
winsize=1;
|
||||
|
||||
vBox->addWidget(tabWidget);
|
||||
vBox->addWidget(win);
|
||||
vBox->activate();
|
||||
|
||||
setExpanded(false);
|
||||
|
||||
connect(win ,SIGNAL(resultSelected(bool)),
|
||||
this,SIGNAL(resultSelected(bool)));
|
||||
|
@ -74,15 +82,7 @@ Kfind::Kfind( QWidget *parent, const char *name, const char *searchPath )
|
|||
this,SLOT(processResults()));
|
||||
connect(&findProcess,SIGNAL(receivedStdout(KProcess *, char *, int)),
|
||||
this, SLOT(handleStdout(KProcess *, char *, int))) ;
|
||||
|
||||
resize(sizeHint());
|
||||
|
||||
// TODO
|
||||
// this hack is needed with Qt 2.0 for some weird reason, probably because
|
||||
// QTabDialog is a dialog and not a simple widget
|
||||
tabDialog->setOkButton(QString::null);
|
||||
tabDialog->recreate(this, 0, QPoint(0, 0));
|
||||
tabDialog->show();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -97,16 +97,6 @@ void Kfind::copySelection() {
|
|||
}
|
||||
|
||||
|
||||
void Kfind::resizeEvent( QResizeEvent *e) {
|
||||
QWidget::resizeEvent(e);
|
||||
|
||||
tabDialog->setGeometry(0,0,
|
||||
width(),(tabDialog->sizeHint()).height());
|
||||
win->setGeometry(0,(tabDialog->sizeHint()).height(),width(),
|
||||
height()-(tabDialog->sizeHint()).height());
|
||||
}
|
||||
|
||||
|
||||
void Kfind::startSearch() {
|
||||
// init buffer
|
||||
if(iBuffer)
|
||||
|
@ -116,11 +106,11 @@ void Kfind::startSearch() {
|
|||
iBuffer[0] = 0;
|
||||
|
||||
QString buffer,pom;
|
||||
//int pos;
|
||||
buffer = tabDialog->createQuery();
|
||||
|
||||
if ( winsize==1)
|
||||
winsize=200;
|
||||
// If this method returns NULL a error occured and
|
||||
// the error message was presented to the user. We just exit.
|
||||
buffer = tabWidget->createQuery();
|
||||
if(buffer == NULL)
|
||||
return;
|
||||
|
||||
emit resultSelected(false);
|
||||
win->clearList();
|
||||
|
@ -128,7 +118,7 @@ void Kfind::startSearch() {
|
|||
emit haveResults(false);
|
||||
|
||||
win->beginSearch();
|
||||
tabDialog->beginSearch();
|
||||
tabWidget->beginSearch();
|
||||
|
||||
if (!buffer.isNull())
|
||||
{
|
||||
|
@ -145,7 +135,7 @@ void Kfind::startSearch() {
|
|||
|
||||
void Kfind::stopSearch() {
|
||||
// printf("Stoping Search\n");
|
||||
tabDialog->endSearch();
|
||||
tabWidget->endSearch();
|
||||
win->doneSearch();
|
||||
|
||||
enableSearchButton(true);
|
||||
|
@ -162,16 +152,15 @@ void Kfind::newSearch() {
|
|||
// printf("Prepare for New Search\n");
|
||||
win->hide(); // !!!!!
|
||||
win->clearList();
|
||||
winsize=1;
|
||||
|
||||
tabDialog->setDefaults();
|
||||
tabWidget->setDefaults();
|
||||
|
||||
emit enableStatusBar(false);
|
||||
emit haveResults(false);
|
||||
emit resultSelected(false);
|
||||
|
||||
setExpanded(false);
|
||||
|
||||
stopSearch();
|
||||
tabDialog->endSearch();
|
||||
tabWidget->endSearch();
|
||||
}
|
||||
|
||||
|
||||
|
@ -189,7 +178,7 @@ void Kfind::handleStdout(KProcess *, char *buffer, int buflen) {
|
|||
// found one file, append it to listbox
|
||||
win->appendResult(iBuffer);
|
||||
if(win->numItems() == 1)
|
||||
emit enableStatusBar(true);
|
||||
setExpanded(false);
|
||||
memmove(iBuffer, p+1, strlen(p + 1)+1);
|
||||
}
|
||||
}
|
||||
|
@ -198,18 +187,30 @@ void Kfind::handleStdout(KProcess *, char *buffer, int buflen) {
|
|||
void Kfind::processResults() {
|
||||
win->show();
|
||||
win->doneSearch();
|
||||
tabDialog->endSearch();
|
||||
tabWidget->endSearch();
|
||||
|
||||
emit haveResults(true);
|
||||
emit enableStatusBar(true);
|
||||
setExpanded(true);
|
||||
|
||||
enableSearchButton(true);
|
||||
}
|
||||
void Kfind::setExpanded(bool expand) {
|
||||
printf("Do it%d \n", expand);
|
||||
|
||||
if(expand) {
|
||||
setMinimumSize(tabWidget->sizeHint().width(),
|
||||
2*tabWidget->sizeHint().height());
|
||||
setMaximumHeight(5000);
|
||||
// win->clearList();
|
||||
win->show();
|
||||
}
|
||||
else {
|
||||
win->hide();
|
||||
setMinimumSize(tabWidget->sizeHint());
|
||||
setMaximumHeight(tabWidget->sizeHint().height());
|
||||
}
|
||||
|
||||
QSize Kfind::sizeHint() {
|
||||
QSize s;
|
||||
s = tabDialog->sizeHint() + QSize(0,winsize-1); // this just doesn't work
|
||||
s.setWidth(520);
|
||||
return s;
|
||||
emit enableStatusBar(expand);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ Q_OBJECT
|
|||
public:
|
||||
Kfind( QWidget * parent = 0 ,const char * name = 0,const char*searchPath = 0);
|
||||
~Kfind();
|
||||
QSize sizeHint();
|
||||
void copySelection();
|
||||
|
||||
public slots:
|
||||
|
@ -47,15 +46,14 @@ signals:
|
|||
void saveResults();
|
||||
|
||||
protected:
|
||||
void resizeEvent( QResizeEvent * );
|
||||
|
||||
private:
|
||||
KShellProcess findProcess;
|
||||
int winsize;
|
||||
KfindTabDialog *tabDialog;
|
||||
KfindTabWidget *tabWidget;
|
||||
KfindWindow * win;
|
||||
|
||||
char *iBuffer;
|
||||
void setExpanded(bool);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -5,21 +5,22 @@
|
|||
***********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <kapp.h>
|
||||
#include <kiconloader.h>
|
||||
#include "ktopwidget.h"
|
||||
#include <kmenubar.h>
|
||||
#include <ktoolbar.h>
|
||||
#include <kstatusbar.h>
|
||||
|
||||
#include <qmessagebox.h>
|
||||
#include <qsize.h>
|
||||
|
||||
#include <qpopupmenu.h>
|
||||
#include <qlayout.h>
|
||||
#include <qpixmap.h>
|
||||
#include <qkeycode.h>
|
||||
#include <qaccel.h>
|
||||
|
||||
#include <kapp.h>
|
||||
#include <kiconloader.h>
|
||||
#include <kmenubar.h>
|
||||
#include <ktoolbar.h>
|
||||
#include <kstatusbar.h>
|
||||
#include <ktmainwindow.h>
|
||||
|
||||
#include "kfoptions.h"
|
||||
#include "kftabdlg.h"
|
||||
#include "kfind.h"
|
||||
|
@ -30,7 +31,7 @@
|
|||
#include "version.h"
|
||||
#include <kglobal.h>
|
||||
|
||||
KfindTop::KfindTop(const char *searchPath) : KTopLevelWidget()
|
||||
KfindTop::KfindTop(const char *searchPath) : KTMainWindow()
|
||||
{
|
||||
// setCaption(QString("KFind ")+KFIND_VERSION);
|
||||
|
||||
|
@ -49,8 +50,6 @@ KfindTop::KfindTop(const char *searchPath) : KTopLevelWidget()
|
|||
setMenu(_mainMenu);
|
||||
_mainMenu->show();
|
||||
|
||||
//_mainMenu->enableMoving(false);
|
||||
|
||||
_statusBar = new KStatusBar( this, "_statusBar");
|
||||
_statusBar->insertItem("0 file(s) found", 0);
|
||||
_statusBar->enable(KStatusBar::Hide);
|
||||
|
@ -79,23 +78,9 @@ KfindTop::KfindTop(const char *searchPath) : KTopLevelWidget()
|
|||
connect(_kfind ,SIGNAL(enableStatusBar(bool)),
|
||||
this,SLOT(enableStatusBar(bool)));
|
||||
|
||||
// No, No, No!!! This is pointless! (sven)
|
||||
// connect(_mainMenu ,SIGNAL(moved(menuPosition)),
|
||||
// this,SLOT(resizeOnFloating()));
|
||||
// connect(_toolBar ,SIGNAL(moved(BarPosition)),
|
||||
// this,SLOT(resizeOnFloating()));
|
||||
|
||||
//_width=(440>_toolBar->width())?440:_toolBar->width();
|
||||
_width=520;
|
||||
//_height=(_kfind->sizeHint()).height(); // Unused as far as I can tell
|
||||
|
||||
// Fixed and Y-fixed guys: Please, please, please stop setting fixed size
|
||||
// on KTW! Fix it on your main view!
|
||||
// sven
|
||||
|
||||
this->enableStatusBar(false); // _kfile emited before connected (sven)
|
||||
|
||||
}; // and what's this semi-colon for? Grrrr!!!! (sven, too)
|
||||
}
|
||||
|
||||
KfindTop::~KfindTop()
|
||||
{
|
||||
|
@ -283,30 +268,13 @@ void KfindTop::enableSearchButton(bool enable)
|
|||
|
||||
void KfindTop::enableStatusBar(bool enable) // rewriten (sven)
|
||||
{
|
||||
/*
|
||||
DON`T LOOK HERE FOR EXAMPLE! IT`S A FORNBIDDEN DANCE!
|
||||
instead please mail me: sven@lisa.exp.univie.ac.at
|
||||
*/
|
||||
//debug ("Wow, what an honour!");
|
||||
if (enable) // we become full-free - win is hsown and set
|
||||
{
|
||||
|
||||
KTopLevelWidget::enableStatusBar(KStatusBar::Show); // implicite update
|
||||
_kfind->resize(_kfind->sizeHint()); // set size
|
||||
_kfind->setMaximumSize(9999, 9999); // set us loos
|
||||
_kfind->setMinimumSize(_kfind->sizeHint()- QSize(0, 200));
|
||||
setMaximumSize(9999, 9999); // kill any constraints
|
||||
adjustSize(); // force us to resizeresizeresizeresizeresize
|
||||
setMinimumSize (size()); // dont' make us smaller
|
||||
|
||||
KTMainWindow::enableStatusBar(KStatusBar::Show); // implicite update
|
||||
}
|
||||
else // we become YFixed - win is hidden
|
||||
{
|
||||
_kfind->resize(width(), _kfind->sizeHint().height());
|
||||
_kfind->setMinimumSize(_kfind->sizeHint());
|
||||
_kfind->setMaximumSize(9999, _kfind->sizeHint().height());
|
||||
KTopLevelWidget::enableStatusBar(KStatusBar::Hide); // updateRects: one
|
||||
updateRects(); // Ooops? Twice?
|
||||
KTMainWindow::enableStatusBar(KStatusBar::Hide); // updateRects: one
|
||||
}
|
||||
}
|
||||
void KfindTop::statusChanged(const char *str)
|
||||
|
@ -321,11 +289,6 @@ void KfindTop::prefs()
|
|||
prefs->show();
|
||||
};
|
||||
|
||||
void KfindTop::resizeOnFloating()
|
||||
{
|
||||
// If someone is more lazy than I am - he doesn't breath. (sven)
|
||||
};
|
||||
|
||||
void KfindTop::copySelection() {
|
||||
if(_kfind)
|
||||
_kfind->copySelection();
|
||||
|
|
|
@ -18,7 +18,7 @@ class Kfind;
|
|||
class QPushButton;
|
||||
class KfindTabDialog;
|
||||
|
||||
class KfindTop: public KTopLevelWidget
|
||||
class KfindTop: public KTMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -35,7 +35,6 @@ public slots:
|
|||
void statusChanged(const char *);
|
||||
void enableSearchButton(bool);
|
||||
void enableStatusBar(bool enable);
|
||||
void resizeOnFloating();
|
||||
|
||||
void copySelection();
|
||||
|
||||
|
|
|
@ -3,33 +3,29 @@
|
|||
* kftabdlg.cpp
|
||||
*
|
||||
**********************************************************************/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <qobjectlist.h>
|
||||
#include <qapplication.h>
|
||||
#include <qtabdialog.h>
|
||||
#include <qmultilinedit.h>
|
||||
#include <qbuttongroup.h>
|
||||
#include <qradiobutton.h>
|
||||
#include <qlabel.h>
|
||||
#include <qcombobox.h>
|
||||
#include <qlayout.h>
|
||||
#include <stdio.h>
|
||||
#include <qstring.h>
|
||||
#include <qfont.h>
|
||||
#include <qtooltip.h>
|
||||
#include <qlineedit.h>
|
||||
#include <qcheckbox.h>
|
||||
#include <qpushbutton.h>
|
||||
#include <qfiledialog.h>
|
||||
#include <qdir.h>
|
||||
#include <qregexp.h>
|
||||
#include <qdatetime.h>
|
||||
#include <qmessagebox.h>
|
||||
#include <qlist.h>
|
||||
#include <qsize.h>
|
||||
#include <qkeycode.h>
|
||||
#include <qdict.h>
|
||||
#include <qvalidator.h>
|
||||
|
||||
#include <kdebug.h>
|
||||
#include <klocale.h>
|
||||
|
@ -39,30 +35,19 @@
|
|||
#include "kftypes.h"
|
||||
#include "kftabdlg.h"
|
||||
|
||||
|
||||
#define FIND_PROGRAM "find"
|
||||
#define SPECIAL_TYPES 7
|
||||
|
||||
extern QList<KfFileType> *types;
|
||||
|
||||
typedef struct GUIItem {
|
||||
QWidget *w;
|
||||
bool enabled;
|
||||
};
|
||||
QList<GUIItem> guiItem;
|
||||
|
||||
void appendGUIItem(QWidget *w) {
|
||||
GUIItem *gi = new GUIItem;
|
||||
|
||||
gi->w = w;
|
||||
guiItem.append(gi);
|
||||
}
|
||||
|
||||
KfindTabDialog::KfindTabDialog( QWidget *parent, const char *name, const char *searchPath )
|
||||
: QTabDialog( parent, name )
|
||||
KfindTabWidget::KfindTabWidget( QWidget *parent, const char *name, const char *searchPath )
|
||||
: QTabWidget( parent, name )
|
||||
{
|
||||
_searchPath = searchPath;
|
||||
|
||||
// This validator will be used for all numeric edit fields
|
||||
KDigitValidator *digitV = new KDigitValidator(this);
|
||||
|
||||
// ************ Page One ************
|
||||
|
||||
pages[0] = new QWidget( this, "page1" );
|
||||
|
@ -94,18 +79,11 @@ KfindTabDialog::KfindTabDialog( QWidget *parent, const char *name, const char *s
|
|||
grid->setColStretch(1,1);
|
||||
grid->activate();
|
||||
|
||||
appendGUIItem(browseB);
|
||||
appendGUIItem(dirBox);
|
||||
appendGUIItem(subdirsCb);
|
||||
appendGUIItem(nameBox);
|
||||
|
||||
// Signals
|
||||
|
||||
|
||||
connect( browseB, SIGNAL(clicked()),
|
||||
this, SLOT(getDirectory()) );
|
||||
|
||||
loadHistory();
|
||||
|
||||
|
||||
addTab( pages[0], i18n(" Name& Location ") );
|
||||
|
||||
// ************ Page Two
|
||||
|
@ -131,14 +109,18 @@ KfindTabDialog::KfindTabDialog( QWidget *parent, const char *name, const char *s
|
|||
|
||||
le[0] ->setText(date2String(QDate(1980,1,1)));
|
||||
le[1] ->setText(date2String(QDate::currentDate()));
|
||||
|
||||
le[2] ->setText("1");
|
||||
le[2] ->setValidator(digitV);
|
||||
|
||||
le[3] ->setText("1");
|
||||
|
||||
le[3] ->setValidator(digitV);
|
||||
|
||||
rb1[0]->setChecked (TRUE);
|
||||
|
||||
bg[0]->insert( rb1[0] );
|
||||
bg[0]->insert( rb1[1] );
|
||||
bg[0]->setExclusive(TRUE);
|
||||
|
||||
bg[1]->insert( rb2[0] );
|
||||
bg[1]->insert( rb2[1] );
|
||||
bg[1]->insert( rb2[2] );
|
||||
|
@ -148,12 +130,8 @@ KfindTabDialog::KfindTabDialog( QWidget *parent, const char *name, const char *s
|
|||
le[2]->setMaxLength(3);
|
||||
le[3]->setMaxLength(3);
|
||||
|
||||
le[0]->setEnabled(modifiedFiles = FALSE);
|
||||
le[1]->setEnabled(betweenDates = FALSE);
|
||||
le[2]->setEnabled(prevMonth = FALSE);
|
||||
le[3]->setEnabled(prevDay = FALSE);
|
||||
|
||||
// Layout
|
||||
|
||||
int tmp = le[0]->fontMetrics().width(" 00/00/0000 ");
|
||||
le[0]->setMinimumSize(tmp, le[0]->sizeHint().height());
|
||||
le[1]->setMinimumSize(tmp, le[1]->sizeHint().height());
|
||||
|
@ -180,31 +158,13 @@ KfindTabDialog::KfindTabDialog( QWidget *parent, const char *name, const char *s
|
|||
|
||||
// Connect
|
||||
|
||||
appendGUIItem(rb1[0]);
|
||||
appendGUIItem(rb1[1]);
|
||||
appendGUIItem(rb2[0]);
|
||||
appendGUIItem(rb2[1]);
|
||||
appendGUIItem(rb2[2]);
|
||||
appendGUIItem(le[0]);
|
||||
appendGUIItem(le[1]);
|
||||
appendGUIItem(le[2]);
|
||||
appendGUIItem(le[3]);
|
||||
|
||||
connect( bg[0], SIGNAL(clicked(int)),
|
||||
this, SLOT(fixLayout()) );
|
||||
connect( bg[1], SIGNAL(clicked(int)),
|
||||
this, SLOT(enableEdit(int)) );
|
||||
connect( rb1[0], SIGNAL(clicked()),
|
||||
this, SLOT(disableAllEdit()) );
|
||||
connect( rb1[1], SIGNAL(clicked()),
|
||||
this, SLOT(enableCheckedEdit()) );
|
||||
|
||||
connect( le[0], SIGNAL(returnPressed()),
|
||||
this, SLOT(isCheckedValid()) );
|
||||
connect( le[1], SIGNAL(returnPressed()),
|
||||
this, SLOT(isCheckedValid()) );
|
||||
connect( le[2], SIGNAL(returnPressed()),
|
||||
this, SLOT(isCheckedValid()) );
|
||||
connect( le[3], SIGNAL(returnPressed()),
|
||||
this, SLOT(isCheckedValid()) );
|
||||
this, SLOT(fixLayout()) );
|
||||
for(int i=0; i<4; i++)
|
||||
connect( le[i], SIGNAL(returnPressed()),
|
||||
parent, SLOT(startSearch()) );
|
||||
|
||||
addTab( pages[1], i18n(" Date Modified ") );
|
||||
|
||||
|
@ -223,6 +183,7 @@ KfindTabDialog::KfindTabDialog( QWidget *parent, const char *name, const char *s
|
|||
caseCb =new QCheckBox(i18n("Case S&ensitive"), pages[2]);
|
||||
|
||||
// Setup
|
||||
|
||||
KfFileType *typ;
|
||||
|
||||
typeBox->insertItem(i18n("All Files and Folders"));
|
||||
|
@ -243,16 +204,19 @@ KfindTabDialog::KfindTabDialog( QWidget *parent, const char *name, const char *s
|
|||
sizeBox ->insertItem( i18n("At Least") );
|
||||
sizeBox ->insertItem( i18n("At Most") );
|
||||
|
||||
sizeEdit->setFixedWidth(50);
|
||||
sizeEdit->setText("1");
|
||||
slotSizeBoxChanged(0);
|
||||
sizeEdit->setMaxLength(5);
|
||||
sizeEdit->setValidator(digitV);
|
||||
|
||||
// Signals
|
||||
|
||||
connect(sizeBox, SIGNAL(highlighted(int)),
|
||||
this, SLOT(slotSizeBoxChanged(int)));
|
||||
// Connect
|
||||
connect( textEdit, SIGNAL(returnPressed()),
|
||||
parent, SLOT(startSearch()) );
|
||||
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], 3, 6, 15, 10 );
|
||||
grid2->addWidget( typeL, 0, 0 );
|
||||
|
@ -268,33 +232,30 @@ KfindTabDialog::KfindTabDialog( QWidget *parent, const char *name, const char *s
|
|||
grid2->setColStretch(6,1);
|
||||
grid2->activate();
|
||||
|
||||
appendGUIItem(textEdit);
|
||||
appendGUIItem(typeBox);
|
||||
appendGUIItem(sizeBox);
|
||||
appendGUIItem(sizeEdit);
|
||||
appendGUIItem(caseCb);
|
||||
|
||||
addTab( pages[2], i18n(" Advanced ") );
|
||||
}
|
||||
|
||||
fixLayout();
|
||||
loadHistory();
|
||||
}
|
||||
|
||||
KfindTabDialog::~KfindTabDialog()
|
||||
KfindTabWidget::~KfindTabWidget()
|
||||
{
|
||||
delete pages[0];
|
||||
delete pages[1];
|
||||
delete pages[2];
|
||||
};
|
||||
|
||||
void KfindTabDialog::loadHistory() {
|
||||
void KfindTabWidget::loadHistory() {
|
||||
// load pattern history
|
||||
KConfig *conf = kapp->getConfig();
|
||||
QStrList sl;
|
||||
conf->setGroup("History");
|
||||
if(conf->readListEntry("Patterns", sl))
|
||||
if(conf->readListEntry("Patterns", sl, ','))
|
||||
nameBox->insertStrList(&sl);
|
||||
else
|
||||
nameBox->insertItem("*");
|
||||
|
||||
if(conf->readListEntry("Directories", sl))
|
||||
if(conf->readListEntry("Directories", sl, ','))
|
||||
{
|
||||
dirBox ->insertItem( _searchPath );
|
||||
dirBox->insertStrList(&sl);
|
||||
|
@ -313,7 +274,7 @@ void KfindTabDialog::loadHistory() {
|
|||
}
|
||||
}
|
||||
|
||||
void KfindTabDialog::saveHistory() {
|
||||
void KfindTabWidget::saveHistory() {
|
||||
// save pattern history
|
||||
QStrList sl;
|
||||
QDict<char> dict(17, FALSE);
|
||||
|
@ -326,7 +287,7 @@ void KfindTabDialog::saveHistory() {
|
|||
}
|
||||
KConfig *conf = kapp->getConfig();
|
||||
conf->setGroup("History");
|
||||
conf->writeEntry("Patterns", sl);
|
||||
conf->writeEntry("Patterns", sl, ',');
|
||||
|
||||
dict.clear();
|
||||
sl.clear();
|
||||
|
@ -337,27 +298,46 @@ void KfindTabDialog::saveHistory() {
|
|||
sl.append(dirBox->text(i).ascii());
|
||||
}
|
||||
}
|
||||
conf->writeEntry("Directories", sl);
|
||||
conf->writeEntry("Directories", sl, ',');
|
||||
}
|
||||
|
||||
void KfindTabDialog::slotSizeBoxChanged(int index) {
|
||||
void KfindTabWidget::slotSizeBoxChanged(int index) {
|
||||
sizeEdit->setEnabled((bool)(index != 0));
|
||||
}
|
||||
|
||||
void KfindTabDialog::keyPressEvent(QKeyEvent *e) {
|
||||
if(e->key() == Key_Escape)
|
||||
return;
|
||||
QTabDialog::keyPressEvent(e);
|
||||
/*
|
||||
Disable/enables the widget by disabling/enabling all pages
|
||||
and all children on the current page
|
||||
*/
|
||||
void KfindTabWidget::setEnabled(bool enabled)
|
||||
{
|
||||
QWidget *curPage = currentPage();
|
||||
// We need to change all but not the current page.
|
||||
// This will preserve current page to be current
|
||||
for(int i=0; i<3; i++)
|
||||
if(pages[i] != curPage)
|
||||
setTabEnabled(pages[i], enabled);
|
||||
|
||||
// Disable the current one now
|
||||
setTabEnabled(curPage, enabled);
|
||||
|
||||
// Diable all children but QGridLayout itself
|
||||
const QObjectList *list = curPage->children();
|
||||
QObjectListIt it( *list );
|
||||
QObject * obj;
|
||||
while ( (obj=it.current()) != 0 ) {
|
||||
++it;
|
||||
if(strcmp("QGridLayout", obj->className()))
|
||||
((QWidget*)obj)->setEnabled( enabled );
|
||||
}
|
||||
|
||||
// If we enable the widget we want to restore
|
||||
// disabled/enabled layout
|
||||
if(enabled)
|
||||
fixLayout();
|
||||
}
|
||||
|
||||
QSize KfindTabDialog::sizeHint()
|
||||
{
|
||||
QSize size(320,195);
|
||||
|
||||
return (size);
|
||||
};
|
||||
|
||||
void KfindTabDialog::setDefaults()
|
||||
void KfindTabWidget::setDefaults()
|
||||
{
|
||||
le[0] ->setText(date2String(QDate(1980,1,1)));
|
||||
le[1] ->setText(date2String(QDate::currentDate()));
|
||||
|
@ -369,267 +349,160 @@ void KfindTabDialog::setDefaults()
|
|||
sizeEdit->setText("1");
|
||||
}
|
||||
|
||||
void KfindTabDialog::enableEdit(int i)
|
||||
{
|
||||
if (!rb1[1]->isChecked())
|
||||
{
|
||||
rb1[0]->setChecked(FALSE);
|
||||
rb1[1]->setChecked(TRUE);
|
||||
}
|
||||
|
||||
disableAllEdit();
|
||||
|
||||
modifiedFiles = TRUE;
|
||||
|
||||
if (i==0)
|
||||
{
|
||||
le[i] ->setEnabled(TRUE);
|
||||
le[i+1]->setEnabled(TRUE);
|
||||
betweenDates = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
i++;
|
||||
le[i]->setEnabled(TRUE);
|
||||
if (i==2)
|
||||
prevMonth = TRUE;
|
||||
else
|
||||
prevDay = TRUE;
|
||||
}
|
||||
/*
|
||||
Checks if dates are correct and popups a error box
|
||||
if they are not.
|
||||
*/
|
||||
bool KfindTabWidget::isDateValid()
|
||||
{
|
||||
if(!(rb1[1]->isChecked() &&
|
||||
rb2[0]->isChecked()))
|
||||
// "Between dates" check box is not checked, nothing to check
|
||||
return TRUE;
|
||||
|
||||
// If we can not parse either of the dates or
|
||||
// "from" date is bigger than "to" date return FALSE.
|
||||
QDate hi1, hi2;
|
||||
if ( string2Date(le[0]->text(), &hi1).isNull() ||
|
||||
string2Date(le[1]->text(), &hi2).isNull() ||
|
||||
hi1 > hi2) {
|
||||
QMessageBox mb(this,"message box");
|
||||
mb.setText( i18n("The date is not valid!!"));
|
||||
mb.show();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void KfindTabDialog::disableAllEdit()
|
||||
QString KfindTabWidget::createQuery()
|
||||
{
|
||||
for (int i=0;i<4;i++)
|
||||
le[i]->setEnabled(FALSE);
|
||||
// If some of the dates are invalid, return NULL
|
||||
if(!isDateValid())
|
||||
return NULL;
|
||||
|
||||
modifiedFiles = FALSE;
|
||||
betweenDates = FALSE;
|
||||
prevMonth = FALSE;
|
||||
prevDay = FALSE;
|
||||
}
|
||||
|
||||
|
||||
void KfindTabDialog::enableCheckedEdit()
|
||||
{
|
||||
for (int i=0;i<3;i++)
|
||||
if (rb2[i]->isChecked())
|
||||
enableEdit(i);
|
||||
}
|
||||
|
||||
void KfindTabDialog::isCheckedValid()
|
||||
{
|
||||
int match, len;
|
||||
QRegExp date("[0-9][0-9]?[/][0-9][0-9]?[/][0-9][0-9][0-9][0-9]");
|
||||
QRegExp r("[0-9]+");
|
||||
|
||||
if (betweenDates == TRUE)
|
||||
{
|
||||
QDate hi, hi2;
|
||||
bool rightDates = TRUE;
|
||||
|
||||
match = date.match(le[0]->text(), 0,&len);
|
||||
if ( !(match != -1 && len == (int)le[0]->text().length() ) )
|
||||
rightDates=FALSE;
|
||||
|
||||
if ( string2Date(le[0]->text(), &hi).isNull() )
|
||||
rightDates=FALSE;
|
||||
|
||||
match = date.match(le[1]->text(), 0,&len);
|
||||
if ( !(match != -1 && len == (int)le[1]->text().length() ) )
|
||||
rightDates=FALSE;
|
||||
|
||||
if ( string2Date(le[1]->text(), &hi).isNull() )
|
||||
rightDates=FALSE;
|
||||
|
||||
if (rightDates)
|
||||
if (string2Date(le[0]->text(), &hi)>string2Date(le[1]->text(), &hi2))
|
||||
rightDates = FALSE;
|
||||
|
||||
if (!rightDates)
|
||||
{
|
||||
QMessageBox mb(this,"message box");
|
||||
mb.setText( i18n("The date is not valid!!"));
|
||||
mb.show();
|
||||
enableSearch = FALSE;
|
||||
};
|
||||
};
|
||||
|
||||
if (prevMonth == TRUE)
|
||||
{
|
||||
match = r.match(le[2]->text(), 0,&len);
|
||||
if ( !(match != -1 && len == (int)le[2]->text().length() ) )
|
||||
{
|
||||
QMessageBox mb(this,"message box");
|
||||
mb.setText( i18n("The month(s) value isn't valid!!"));
|
||||
mb.show();
|
||||
enableSearch = FALSE;
|
||||
};
|
||||
};
|
||||
if (prevDay == TRUE)
|
||||
{
|
||||
match = r.match(le[3]->text(), 0,&len);
|
||||
if (! (match != -1 && len == (int)le[3]->text().length() ) )
|
||||
{
|
||||
QMessageBox mb(this,"message box");
|
||||
mb.setText( i18n("The day(s) value isn't valid!!"));
|
||||
mb.show();
|
||||
enableSearch = FALSE;
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
void KfindTabDialog::checkSize()
|
||||
{
|
||||
int match,len;
|
||||
QRegExp r("[0-9]+");
|
||||
|
||||
match = r.match(sizeEdit->text(), 0,&len);
|
||||
if ( !(match != -1 && len == (int)sizeEdit->text().length() ) )
|
||||
{
|
||||
QMessageBox mb(this,"message box");
|
||||
mb.setText( i18n("The value in size isn't valid number!!"));
|
||||
mb.show();
|
||||
enableSearch = FALSE;
|
||||
};
|
||||
};
|
||||
|
||||
QString KfindTabDialog::createQuery()
|
||||
{
|
||||
QString str,pom;
|
||||
int month;
|
||||
char *type;
|
||||
|
||||
enableSearch = TRUE;
|
||||
isCheckedValid();
|
||||
checkSize();
|
||||
|
||||
str = FIND_PROGRAM;
|
||||
str += " ";
|
||||
|
||||
if (enableSearch)
|
||||
{
|
||||
// str += dirBox->text(dirBox->currentItem());
|
||||
// printf("Tak co je v tom boxu: %s\n",dirBox->currentText());
|
||||
str += dirBox->currentText();
|
||||
str += dirBox->currentText();
|
||||
|
||||
QString str1;
|
||||
str1 += " \"(\" -name \"";
|
||||
// str1 += nameBox->text(nameBox->currentItem());
|
||||
QString str1;
|
||||
str1 += " \"(\" -name \"";
|
||||
|
||||
if(nameBox->currentText().isEmpty())
|
||||
str1 += "*";
|
||||
else
|
||||
str1 += nameBox->currentText();
|
||||
str1 += "\" \")\"";
|
||||
str1 += " ";
|
||||
if(nameBox->currentText().isEmpty())
|
||||
str1 += "*";
|
||||
else
|
||||
str1 += nameBox->currentText();
|
||||
str1 += "\" \")\"";
|
||||
str1 += " ";
|
||||
|
||||
switch(typeBox->currentItem()) {
|
||||
case 0: // all files
|
||||
break;
|
||||
switch(typeBox->currentItem()) {
|
||||
case 0: // all files
|
||||
break;
|
||||
|
||||
case 1: // files
|
||||
str1 += "-type f";
|
||||
break;
|
||||
|
||||
case 2: // folders
|
||||
str1 += "-type d";
|
||||
break;
|
||||
|
||||
case 3: // symlink
|
||||
str1 += "-type l";
|
||||
break;
|
||||
|
||||
case 4: // special file
|
||||
str1 += "-type p -or -type s -or -type b or -type c";
|
||||
break;
|
||||
|
||||
case 5: // executables
|
||||
str1 += "-perm +111 -type f";
|
||||
break;
|
||||
|
||||
case 6: // suid binaries
|
||||
str1 += "-perm +6000 -type f";
|
||||
break;
|
||||
|
||||
default: {
|
||||
str1 = "";
|
||||
KfFileType *typ;
|
||||
|
||||
typ = types->first();
|
||||
for (int i=SPECIAL_TYPES; i<typeBox->currentItem(); i++ )
|
||||
typ = types->next();
|
||||
// printf("Take filetype: %s\n",typ->getComment("").ascii());
|
||||
|
||||
QStrList& pats = typ->getPattern();
|
||||
bool firstpattern = FALSE;
|
||||
str += " \"(\" ";
|
||||
for (QString pattern=pats.first(); pattern!=0L;
|
||||
pattern=pats.next())
|
||||
{
|
||||
if (!firstpattern)
|
||||
{
|
||||
str += " -name ";
|
||||
firstpattern=TRUE;
|
||||
}
|
||||
else
|
||||
str += " -o -name ";
|
||||
|
||||
if ( pattern.find("*",0)==0 )
|
||||
{
|
||||
str += nameBox->text(nameBox->currentItem());
|
||||
str += "\"" + pattern + "\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
str += "\"" + pattern + "\"";
|
||||
str += nameBox->text(nameBox->currentItem());
|
||||
};
|
||||
};
|
||||
str += " \")\"";
|
||||
|
||||
// printf("Query : %s\n",str.ascii());
|
||||
}
|
||||
}
|
||||
|
||||
str += str1;
|
||||
|
||||
if (!subdirsCb->isChecked())
|
||||
str.append(" -maxdepth 1 ");
|
||||
|
||||
if (modifiedFiles)
|
||||
{
|
||||
if (betweenDates == TRUE)
|
||||
{
|
||||
QDate q1, q2;
|
||||
str.append(pom.sprintf(" -daystart -mtime -%d -mtime +%d",
|
||||
(string2Date(le[0]->text(),&q1)).daysTo(QDate::currentDate()),
|
||||
(string2Date(le[1]->text(),&q2)).daysTo(QDate::currentDate()) ));
|
||||
};
|
||||
|
||||
if (prevMonth == TRUE)
|
||||
{
|
||||
sscanf(le[2]->text().ascii(),"%d",&month);
|
||||
str.append(pom = QString(" -daystart -mtime -%1 ")
|
||||
.arg((int)(month*30.416667)));
|
||||
};
|
||||
|
||||
if (prevDay == TRUE)
|
||||
str.append(pom = QString(" -daystart -mtime -%1").arg(le[3]->text()));
|
||||
};
|
||||
case 1: // files
|
||||
str1 += "-type f";
|
||||
break;
|
||||
|
||||
case 2: // folders
|
||||
str1 += "-type d";
|
||||
break;
|
||||
|
||||
case 3: // symlink
|
||||
str1 += "-type l";
|
||||
break;
|
||||
|
||||
case 4: // special file
|
||||
str1 += "-type p -or -type s -or -type b or -type c";
|
||||
break;
|
||||
|
||||
case 5: // executables
|
||||
str1 += "-perm +111 -type f";
|
||||
break;
|
||||
|
||||
case 6: // suid binaries
|
||||
str1 += "-perm +6000 -type f";
|
||||
break;
|
||||
|
||||
default: {
|
||||
str1 = "";
|
||||
KfFileType *typ;
|
||||
|
||||
typ = types->first();
|
||||
for (int i=SPECIAL_TYPES; i<typeBox->currentItem(); i++ )
|
||||
typ = types->next();
|
||||
// printf("Take filetype: %s\n",typ->getComment("").ascii());
|
||||
|
||||
QStrList& pats = typ->getPattern();
|
||||
bool firstpattern = FALSE;
|
||||
str += " \"(\" ";
|
||||
for (QString pattern=pats.first(); pattern!=0L;
|
||||
pattern=pats.next())
|
||||
{
|
||||
if (!firstpattern)
|
||||
{
|
||||
str += " -name ";
|
||||
firstpattern=TRUE;
|
||||
}
|
||||
else
|
||||
str += " -o -name ";
|
||||
|
||||
if ( pattern.find("*",0)==0 )
|
||||
{
|
||||
str += nameBox->text(nameBox->currentItem());
|
||||
str += "\"" + pattern + "\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
str += "\"" + pattern + "\"";
|
||||
str += nameBox->text(nameBox->currentItem());
|
||||
};
|
||||
};
|
||||
str += " \")\"";
|
||||
}
|
||||
}
|
||||
|
||||
str += str1;
|
||||
|
||||
if (!subdirsCb->isChecked())
|
||||
str.append(" -maxdepth 1 ");
|
||||
|
||||
if (rb1[1]->isChecked()) // Modified
|
||||
{
|
||||
if (rb2[0]->isChecked()) // Between dates
|
||||
{
|
||||
QDate q1, q2;
|
||||
str.append(pom.sprintf(" -daystart -mtime -%d -mtime +%d",
|
||||
(string2Date(le[0]->text(),&q1)).daysTo(QDate::currentDate()),
|
||||
(string2Date(le[1]->text(),&q2)).daysTo(QDate::currentDate()) ));
|
||||
}
|
||||
else
|
||||
if (rb2[1]->isChecked()) // Previous mounth
|
||||
{
|
||||
sscanf(le[2]->text().ascii(),"%d",&month);
|
||||
str.append(pom = QString(" -daystart -mtime -%1 ")
|
||||
.arg((int)(month*30.416667)));
|
||||
}
|
||||
else
|
||||
if (rb2[2]->isChecked()) // Previous day
|
||||
str.append(pom = QString(" -daystart -mtime -%1").arg(le[3]->text()));
|
||||
|
||||
|
||||
if (sizeBox->currentItem() != 0)
|
||||
{
|
||||
switch(sizeBox->currentItem())
|
||||
{
|
||||
case 1: {type=(char *)(sizeEdit->text().toInt()==0?"":"+");break;}
|
||||
case 2: {type=(char *)(sizeEdit->text().toInt()==0?"":"-"); break;}
|
||||
default: {type=(char *)(sizeEdit->text().toInt()==0?"":" ");}
|
||||
};
|
||||
case 1: {type=(char *)(sizeEdit->text().toInt()==0?"":"+");break;}
|
||||
case 2: {type=(char *)(sizeEdit->text().toInt()==0?"":"-"); break;}
|
||||
default: {type=(char *)(sizeEdit->text().toInt()==0?"":" ");}
|
||||
}
|
||||
str.append(pom = QString(" -size %1%2k ").arg(type).arg(sizeEdit->text()));
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if(!textEdit->text().isEmpty()) {
|
||||
str += "|xargs egrep -l";
|
||||
|
@ -647,25 +520,26 @@ QString KfindTabDialog::createQuery()
|
|||
};
|
||||
|
||||
|
||||
QString KfindTabDialog::date2String(QDate date)
|
||||
QString KfindTabWidget::date2String(QDate date)
|
||||
{
|
||||
QString str;
|
||||
|
||||
str.sprintf("%.2d/%.2d/%4d",date.day(),date.month(),date.year());
|
||||
return(str);
|
||||
};
|
||||
}
|
||||
|
||||
QDate &KfindTabDialog::string2Date(QString str, QDate *qd)
|
||||
QDate &KfindTabWidget::string2Date(QString str, QDate *qd)
|
||||
{
|
||||
int year,month,day;
|
||||
|
||||
sscanf(str.ascii(),"%2d/%2d/%4d",&day,&month,&year);
|
||||
qd->setYMD(year, month, day);
|
||||
|
||||
// If we can not scan exactly 3 integers do not try to parse
|
||||
if(sscanf(str.ascii(),"%2d/%2d/%4d",&day,&month,&year) == 3)
|
||||
qd->setYMD(year, month, day);
|
||||
return *qd;
|
||||
|
||||
}
|
||||
|
||||
void KfindTabDialog::getDirectory()
|
||||
void KfindTabWidget::getDirectory()
|
||||
{
|
||||
QString result;
|
||||
|
||||
|
@ -685,16 +559,60 @@ void KfindTabDialog::getDirectory()
|
|||
};
|
||||
};
|
||||
|
||||
void KfindTabDialog::beginSearch() {
|
||||
void KfindTabWidget::beginSearch() {
|
||||
saveHistory();
|
||||
for(GUIItem *g = guiItem.first(); g; g = guiItem.next()) {
|
||||
g->enabled = g->w->isEnabled();
|
||||
g->w->setEnabled(FALSE);
|
||||
}
|
||||
setEnabled( FALSE );
|
||||
}
|
||||
|
||||
void KfindTabDialog::endSearch() {
|
||||
for(GUIItem *g = guiItem.first(); g; g = guiItem.next())
|
||||
g->w->setEnabled(g->enabled);
|
||||
void KfindTabWidget::endSearch() {
|
||||
setEnabled( TRUE );
|
||||
loadHistory();
|
||||
}
|
||||
|
||||
/*
|
||||
Disables/enables all edit fields depending on their
|
||||
respective check buttons.
|
||||
*/
|
||||
void KfindTabWidget::fixLayout() {
|
||||
// If "All files" is checked - disable all edits on page two
|
||||
if(rb1[0]->isChecked())
|
||||
{
|
||||
for (int i=0;i<4;i++)
|
||||
le[i]->setEnabled(FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
le[0]->setEnabled(rb2[0]->isChecked());
|
||||
le[1]->setEnabled(rb2[0]->isChecked());
|
||||
le[2]->setEnabled(rb2[1]->isChecked());
|
||||
le[3]->setEnabled(rb2[2]->isChecked());
|
||||
}
|
||||
|
||||
// Size box on page three
|
||||
sizeEdit->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->match( input ) < 0 )
|
||||
{
|
||||
// Beep on user if he enters non-digit
|
||||
QApplication::beep();
|
||||
return QValidator::Invalid;
|
||||
}
|
||||
else
|
||||
return QValidator::Acceptable;
|
||||
}
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
#ifndef KFTABDLG_H
|
||||
#define KFTABDLG_H
|
||||
|
||||
#include <qtabdialog.h>
|
||||
#include <qtabwidget.h>
|
||||
#include <qvalidator.h>
|
||||
|
||||
class QButtonGroup;
|
||||
class QPushButton;
|
||||
class QRadioButton;
|
||||
class KfDirDialog;
|
||||
class QLabel;
|
||||
class QComboBox;
|
||||
class QCheckBox;
|
||||
|
@ -20,38 +20,28 @@ class QLineEdit;
|
|||
class QString;
|
||||
class QDate;
|
||||
class QSize;
|
||||
class QRegExp;
|
||||
|
||||
class KfindTabDialog: public QTabDialog
|
||||
class KfDirDialog;
|
||||
|
||||
class KfindTabWidget: public QTabWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
KfindTabDialog(QWidget * parent = 0,const char * name = 0,const char*searchPath=0);
|
||||
virtual ~KfindTabDialog();
|
||||
KfindTabWidget(QWidget * parent = 0,const char * name = 0,const char*searchPath=0);
|
||||
virtual ~KfindTabWidget();
|
||||
QString createQuery();
|
||||
QSize sizeHint();
|
||||
void setDefaults();
|
||||
|
||||
virtual void keyPressEvent(QKeyEvent *);
|
||||
|
||||
|
||||
void beginSearch();
|
||||
void endSearch();
|
||||
void loadHistory();
|
||||
void saveHistory();
|
||||
|
||||
private slots:
|
||||
// Slots for first page
|
||||
void getDirectory();
|
||||
|
||||
// Slots for second page
|
||||
void enableEdit(int);
|
||||
void disableAllEdit();
|
||||
void enableCheckedEdit();
|
||||
void isCheckedValid();
|
||||
|
||||
// Slots for third page
|
||||
void checkSize();
|
||||
|
||||
void fixLayout();
|
||||
void slotSizeBoxChanged(int);
|
||||
|
||||
signals:
|
||||
|
@ -59,19 +49,15 @@ signals:
|
|||
protected:
|
||||
|
||||
private:
|
||||
void setEnabled(bool);
|
||||
bool isDateValid();
|
||||
|
||||
QString date2String(QDate);
|
||||
QDate &string2Date(QString, QDate *);
|
||||
|
||||
bool modifiedFiles;
|
||||
bool betweenDates;
|
||||
bool prevMonth;
|
||||
bool prevDay;
|
||||
|
||||
bool enableSearch;
|
||||
|
||||
QWidget *pages[3];
|
||||
|
||||
// for firts page
|
||||
// for first page
|
||||
QLabel *namedL;
|
||||
QComboBox *nameBox;
|
||||
QLabel *lookinL;
|
||||
|
@ -103,4 +89,18 @@ private:
|
|||
QString _searchPath;
|
||||
};
|
||||
|
||||
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
|
||||
|
|
139
kfind/kfwin.cpp
139
kfind/kfwin.cpp
|
@ -53,52 +53,24 @@
|
|||
extern KfSaveOptions *saving;
|
||||
extern QList<KfArchiver> *archivers;
|
||||
|
||||
class MyQListBox : public QListBox {
|
||||
public:
|
||||
MyQListBox(QWidget *parent, const char *name) :
|
||||
QListBox(parent, name) {
|
||||
}
|
||||
|
||||
virtual bool eventFilter(QObject *, QEvent *e) {
|
||||
if(e->type() == QEvent::KeyPress || e->type() == QEvent::Accel) {
|
||||
QKeyEvent *k = (QKeyEvent *)e;
|
||||
if(k->key() == Key_PageUp ||
|
||||
k->key() == Key_PageDown) {
|
||||
keyPressEvent(k);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
KfindWindow::KfindWindow( QWidget *parent, const char *name )
|
||||
: QWidget( parent, name )
|
||||
: QListBox( parent, name )
|
||||
{
|
||||
lbx = new MyQListBox(this,"list_box" );
|
||||
topLevelWidget()->installEventFilter(lbx);
|
||||
lbx->setMultiSelection(FALSE);
|
||||
// topLevelWidget()->installEventFilter(lbx);
|
||||
setMultiSelection(FALSE);
|
||||
|
||||
connect(lbx , SIGNAL(highlighted(int)),
|
||||
connect(this , SIGNAL(highlighted(int)),
|
||||
this, SLOT(highlighted()) );
|
||||
connect(lbx , SIGNAL(selected(int)),
|
||||
connect(this, SIGNAL(selected(int)),
|
||||
this, SLOT( openBinding()) );
|
||||
};
|
||||
|
||||
KfindWindow::~KfindWindow()
|
||||
{
|
||||
delete lbx;
|
||||
};
|
||||
|
||||
void KfindWindow::resizeEvent( QResizeEvent * )
|
||||
{
|
||||
lbx->setGeometry(0,0,width(),height());
|
||||
};
|
||||
|
||||
void KfindWindow::appendResult(const char *file) {
|
||||
lbx->insertItem(file);
|
||||
insertItem(file);
|
||||
}
|
||||
|
||||
void KfindWindow::beginSearch() {
|
||||
|
@ -109,13 +81,13 @@ void KfindWindow::beginSearch() {
|
|||
void KfindWindow::doneSearch() {
|
||||
killTimers();
|
||||
|
||||
QString str = i18n("%1 file(s) found").arg(lbx->count());
|
||||
QString str = i18n("%1 file(s) found").arg(count());
|
||||
emit statusChanged(str.ascii());
|
||||
}
|
||||
|
||||
void KfindWindow::timerEvent(QTimerEvent *) {
|
||||
if(lbx->count() > 0) {
|
||||
QString str = i18n("%1 file(s) found").arg(lbx->count());
|
||||
if(count() > 0) {
|
||||
QString str = i18n("%1 file(s) found").arg(count());
|
||||
emit statusChanged(str.ascii());
|
||||
}
|
||||
}
|
||||
|
@ -140,7 +112,7 @@ void KfindWindow::updateResults(const char *file )
|
|||
return;
|
||||
};
|
||||
|
||||
lbx->clear();
|
||||
clear();
|
||||
|
||||
count=0;
|
||||
while ( !feof( f ) )
|
||||
|
@ -161,7 +133,7 @@ void KfindWindow::updateResults(const char *file )
|
|||
if (!(filename->exists()))
|
||||
strl->removeLast();
|
||||
|
||||
lbx->insertStrList(strl,-1);
|
||||
insertStrList(strl,-1);
|
||||
QString statusmsg = i18n("%1 file(s) found").arg(count);
|
||||
emit statusChanged(statusmsg.ascii());
|
||||
|
||||
|
@ -174,9 +146,9 @@ void KfindWindow::updateResults(const char *file )
|
|||
// copy to clipboard aka X11 selection
|
||||
void KfindWindow::copySelection() {
|
||||
QString s;
|
||||
for(int i = 0; i < (int)lbx->count(); i++)
|
||||
if(lbx->isSelected(i)) {
|
||||
s.append(lbx->text(i));
|
||||
for(int i = 0; i < (int)count(); i++)
|
||||
if(isSelected(i)) {
|
||||
s.append(text(i));
|
||||
s.append(" ");
|
||||
}
|
||||
|
||||
|
@ -189,42 +161,43 @@ void KfindWindow::copySelection() {
|
|||
|
||||
void KfindWindow::clearList()
|
||||
{
|
||||
lbx->clear();
|
||||
clear();
|
||||
};
|
||||
|
||||
void KfindWindow::changeItem(const char *itemName)
|
||||
{
|
||||
lbx->changeItem(itemName,lbx->currentItem());
|
||||
debug("CXHANGE ITEM CALLED\n");
|
||||
// changeItem(itemName,currentItem());
|
||||
};
|
||||
|
||||
void KfindWindow::selectAll() {
|
||||
lbx->setAutoUpdate(FALSE);
|
||||
if(lbx->currentItem() == -1)
|
||||
lbx->setCurrentItem(0);
|
||||
for(int i = 0; i < (int)lbx->count(); i++)
|
||||
lbx->setSelected(i, TRUE);
|
||||
lbx->setAutoUpdate(TRUE);
|
||||
lbx->repaint();
|
||||
setAutoUpdate(FALSE);
|
||||
if(currentItem() == -1)
|
||||
setCurrentItem(0);
|
||||
for(int i = 0; i < (int)count(); i++)
|
||||
setSelected(i, TRUE);
|
||||
setAutoUpdate(TRUE);
|
||||
repaint();
|
||||
}
|
||||
|
||||
void KfindWindow::invertSelection() {
|
||||
lbx->setAutoUpdate(FALSE);
|
||||
if(lbx->currentItem() == -1)
|
||||
lbx->setCurrentItem(0);
|
||||
for(int i = 0; i < (int)lbx->count(); i++)
|
||||
lbx->setSelected(i, !lbx->isSelected(i));
|
||||
lbx->setAutoUpdate(TRUE);
|
||||
lbx->repaint();
|
||||
setAutoUpdate(FALSE);
|
||||
if(currentItem() == -1)
|
||||
setCurrentItem(0);
|
||||
for(int i = 0; i < (int)count(); i++)
|
||||
setSelected(i, !isSelected(i));
|
||||
setAutoUpdate(TRUE);
|
||||
repaint();
|
||||
}
|
||||
|
||||
void KfindWindow::unselectAll() {
|
||||
lbx->setAutoUpdate(FALSE);
|
||||
if(lbx->currentItem() == -1)
|
||||
lbx->setCurrentItem(0);
|
||||
for(int i = 0; i < (int)lbx->count(); i++)
|
||||
lbx->setSelected(i, FALSE);
|
||||
lbx->setAutoUpdate(TRUE);
|
||||
lbx->repaint();
|
||||
setAutoUpdate(FALSE);
|
||||
if(currentItem() == -1)
|
||||
setCurrentItem(0);
|
||||
for(int i = 0; i < (int)count(); i++)
|
||||
setSelected(i, FALSE);
|
||||
setAutoUpdate(TRUE);
|
||||
repaint();
|
||||
}
|
||||
|
||||
void KfindWindow::saveResults()
|
||||
|
@ -243,7 +216,7 @@ void KfindWindow::saveResults()
|
|||
|
||||
results=fopen(filename.ascii(),"w");
|
||||
|
||||
items=lbx->count();
|
||||
items=count();
|
||||
if (results==0L)
|
||||
QMessageBox::warning(parentWidget(),i18n("Error"),
|
||||
i18n("It wasn't possible to save results!"),
|
||||
|
@ -265,7 +238,7 @@ void KfindWindow::saveResults()
|
|||
while(item!=items)
|
||||
{
|
||||
fprintf(results,"<DT><A HREF=\"file:%s\">file:%s</A>\n",
|
||||
lbx->text(item).ascii(),lbx->text(item).ascii());
|
||||
text(item).ascii(),text(item).ascii());
|
||||
item++;
|
||||
};
|
||||
fprintf(results,"</DL><P></BODY></HTML>\n");
|
||||
|
@ -275,7 +248,7 @@ void KfindWindow::saveResults()
|
|||
item=0;
|
||||
while(item!=items)
|
||||
{
|
||||
fprintf(results,"%s\n", lbx->text(item).ascii());
|
||||
fprintf(results,"%s\n", text(item).ascii());
|
||||
item++;
|
||||
};
|
||||
|
||||
|
@ -297,13 +270,13 @@ void KfindWindow::highlighted()
|
|||
void KfindWindow::deleteFiles()
|
||||
{
|
||||
QString tmp = i18n("Do you really want to delete file:\n%1")
|
||||
.arg(lbx->text(lbx->currentItem()));
|
||||
.arg(text(currentItem()));
|
||||
if (!QMessageBox::information(parentWidget(),
|
||||
i18n("Delete File - Find Files"),
|
||||
tmp, i18n("&Yes"), i18n("&No"), 0,
|
||||
1))
|
||||
{
|
||||
QFileInfo *file = new QFileInfo(lbx->text(lbx->currentItem()));
|
||||
QFileInfo *file = new QFileInfo(text(currentItem()));
|
||||
if (file->isFile()||file->isSymLink())
|
||||
{
|
||||
if (remove(file->filePath().ascii())==-1)
|
||||
|
@ -326,8 +299,8 @@ void KfindWindow::deleteFiles()
|
|||
// KFM *kfm= new KFM();
|
||||
#warning "TODO : implement a replacement for kfm->refreshDirectory(url)"
|
||||
// and replace the one below as well
|
||||
// kfm->refreshDirectory(lbx->text(lbx->currentItem()));
|
||||
lbx->removeItem(lbx->currentItem());
|
||||
// kfm->refreshDirectory(text(currentItem()));
|
||||
removeItem(currentItem());
|
||||
// delete kfm;
|
||||
};
|
||||
}
|
||||
|
@ -354,8 +327,8 @@ void KfindWindow::deleteFiles()
|
|||
else
|
||||
{
|
||||
// KFM *kfm= new KFM();
|
||||
// kfm->refreshDirectory(lbx->text(lbx->currentItem()));
|
||||
lbx->removeItem(lbx->currentItem());
|
||||
// kfm->refreshDirectory(text(currentItem()));
|
||||
removeItem(currentItem());
|
||||
// delete kfm;
|
||||
};
|
||||
};
|
||||
|
@ -368,11 +341,11 @@ void KfindWindow::fileProperties()
|
|||
{
|
||||
QString tmp= "file:";
|
||||
|
||||
QFileInfo *fileInfo = new QFileInfo(lbx->text(lbx->currentItem()));
|
||||
QFileInfo *fileInfo = new QFileInfo(text(currentItem()));
|
||||
if (fileInfo->isDir())
|
||||
tmp.append(fileInfo->filePath());
|
||||
else
|
||||
tmp.append(lbx->text(lbx->currentItem()));
|
||||
tmp.append(text(currentItem()));
|
||||
(void) new PropertiesDialog(tmp);
|
||||
};
|
||||
|
||||
|
@ -380,7 +353,7 @@ void KfindWindow::openFolder()
|
|||
{
|
||||
QString tmp;
|
||||
|
||||
QFileInfo *fileInfo = new QFileInfo(lbx->text(lbx->currentItem()));
|
||||
QFileInfo *fileInfo = new QFileInfo(text(currentItem()));
|
||||
if (fileInfo->isDir())
|
||||
tmp = "file:" + fileInfo->filePath();
|
||||
else
|
||||
|
@ -393,11 +366,11 @@ void KfindWindow::openBinding()
|
|||
{
|
||||
QString tmp= "file:";
|
||||
|
||||
QFileInfo *fileInfo = new QFileInfo(lbx->text(lbx->currentItem()));
|
||||
QFileInfo *fileInfo = new QFileInfo(text(currentItem()));
|
||||
if (fileInfo->isDir())
|
||||
tmp.append(fileInfo->filePath());
|
||||
else
|
||||
tmp.append(lbx->text(lbx->currentItem()));
|
||||
tmp.append(text(currentItem()));
|
||||
(void) new KRun( tmp );
|
||||
};
|
||||
|
||||
|
@ -458,7 +431,7 @@ void KfindWindow::execAddToArchive(KfArchiver *arch,QString archname)
|
|||
|
||||
if ( pom=="%d" )
|
||||
{
|
||||
QFileInfo *fileInfo = new QFileInfo(lbx->text(lbx->currentItem()));
|
||||
QFileInfo *fileInfo = new QFileInfo(text(currentItem()));
|
||||
pom = fileInfo->dirPath(TRUE)+"/";
|
||||
};
|
||||
|
||||
|
@ -466,11 +439,11 @@ void KfindWindow::execAddToArchive(KfArchiver *arch,QString archname)
|
|||
pom = archname;
|
||||
|
||||
if ( pom=="%f" )
|
||||
pom = lbx->text(lbx->currentItem());
|
||||
pom = text(currentItem());
|
||||
|
||||
if ( pom=="%n" )
|
||||
{
|
||||
QFileInfo *fileInfo = new QFileInfo(lbx->text(lbx->currentItem()));
|
||||
QFileInfo *fileInfo = new QFileInfo(text(currentItem()));
|
||||
pom = fileInfo->fileName();
|
||||
};
|
||||
|
||||
|
@ -486,5 +459,5 @@ void KfindWindow::execAddToArchive(KfArchiver *arch,QString archname)
|
|||
};
|
||||
|
||||
int KfindWindow::numItems() {
|
||||
return lbx->count();
|
||||
return count();
|
||||
}
|
||||
|
|
|
@ -7,20 +7,11 @@
|
|||
#ifndef KFWIN_H
|
||||
#define KFWIN_H
|
||||
|
||||
#include <qwidget.h>
|
||||
#include <qdialog.h>
|
||||
#include <qlistbox.h>
|
||||
|
||||
class QListBox;
|
||||
class QLabel;
|
||||
class QDialog;
|
||||
class QGroupBox;
|
||||
class QCheckBox;
|
||||
class QString;
|
||||
class QLineEdit;
|
||||
class QFileInfo;
|
||||
class KfArchiver;
|
||||
|
||||
class KfindWindow: public QWidget
|
||||
class KfindWindow: public QListBox
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -57,14 +48,12 @@ private slots:
|
|||
void openBinding();
|
||||
|
||||
protected:
|
||||
void resizeEvent( QResizeEvent * );
|
||||
|
||||
signals:
|
||||
void resultSelected(bool);
|
||||
void statusChanged(const char *);
|
||||
|
||||
private:
|
||||
QListBox * lbx;
|
||||
void execAddToArchive(KfArchiver *arch,QString filename);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue