Source Code (Use browser search to find items of interest.)

Class Index

kfind'Kfind (./kdeutils/kfind/kfind.h:17)

class Kfind: public QWidget
{
Q_OBJECT

public:
  Kfind( QWidget * parent = 0 ,const char * name = 0, const QString & searchPath = 0);
  ~Kfind();
  void copySelection();

public slots:
  void startSearch();
  void stopSearch();
  void newSearch();
  void handleStdout(KProcess *proc, char *buffer, int buflen);
  void setFocus() { tabWidget->setFocus(); }

signals:
  void  haveResults(bool);
  void  resultSelected(bool);
  void  statusChanged(const char *);
  void  enableSearchButton(bool);
  void  enableStatusBar(bool);

  void open();
  void addToArchive();
  void deleteFile();
  void renameFile();
  void properties();
  void openFolder();
  void saveResults();

protected:
  /**
   * Pressing Escape stops searching
   */
  virtual void keyReleaseEvent(QKeyEvent *e);

private:
  KShellProcess *findProcess;
  KfindTabWidget *tabWidget;
  KfindWindow * win;

  bool isResultReported;
  bool hasBeenKilled;
  char *iBuffer;
  void setExpanded(bool);
};

kfind'Kfind::Kfind() (./kdeutils/kfind/kfind.cpp:38)

Kfind::Kfind( QWidget *parent, const char *name, const QString & searchPath )
  : QWidget( parent, name )
{
  // init IO buffer
  iBuffer = new char[IBUFSIZE];
  isResultReported = false;

  // create tabwidget
  tabWidget = new KfindTabWidget(this,"dialog",searchPath);

  // prepare window for find results
  win = new KfindWindow(this,"window");

  QVBoxLayout *vBox = new QVBoxLayout(this);
  vBox->addWidget(tabWidget);
  vBox->addWidget(win);
  vBox->activate();

  setExpanded(false);

  connect(win ,SIGNAL(resultSelected(bool)),
	  this,SIGNAL(resultSelected(bool)));
  connect(this,SIGNAL(deleteFile()),
	  win,SLOT(deleteFiles()));
  connect(this,SIGNAL(properties()),
	  win,SLOT(fileProperties()));
  connect(this,SIGNAL(openFolder()),
	  win,SLOT(openFolder()));
  connect(this,SIGNAL(saveResults()),
	  win,SLOT(saveResults()));
  connect(this,SIGNAL(addToArchive()),
	  win,SLOT(addToArchive()));
  connect(this,SIGNAL(open()),
	  win,SLOT(openBinding()));
  connect(parentWidget(),SIGNAL(selectAll()),
	  win,SLOT(selectAll()));
  connect(parentWidget(),SIGNAL(unselectAll()),
	  win,SLOT(unselectAll()));

  // We want to use /bin/sh as a shell. With tcsh and csh
  // find process can not be stopped by kill() call.
  findProcess = new KShellProcess("/bin/sh");

  connect(findProcess, SIGNAL(processExited(KProcess *)),
	  this, SLOT(stopSearch()));
  connect(findProcess, SIGNAL(receivedStdout(KProcess *, char *, int)),
	  this, SLOT(handleStdout(KProcess *, char *, int))) ;
}


kfind'Kfind::~Kfind() (./kdeutils/kfind/kfind.cpp:87)

Kfind::~Kfind() {
  delete [] iBuffer;
  delete findProcess;
}


kfind'Kfind::startSearch() (./kdeutils/kfind/kfind.cpp:92)

void Kfind::startSearch() {

  // If this method returns NULL a error occured and
  // the error message was presented to the user. We just exit.
  QString cmdline = tabWidget->createQuery();
  if(cmdline == NULL)
    return;

  iBuffer[0] = 0;
  isResultReported = false;
  hasBeenKilled = false;

  // Reset count
  QString str = i18n("%1 files found").arg(0);
  emit statusChanged(str);

  emit resultSelected(false);
  emit haveResults(false);
  emit enableSearchButton(false);

  win->beginSearch();
  tabWidget->beginSearch();

  setExpanded(true);

  findProcess->clearArguments();
  findProcess->setExecutable(cmdline);
  findProcess->start(KProcess::NotifyOnExit, KProcess::AllOutput);
}


kfind'Kfind::stopSearch() (./kdeutils/kfind/kfind.cpp:122)

void Kfind::stopSearch() {
  emit enableSearchButton(true);

  win->endSearch();
  tabWidget->endSearch();

  if(findProcess->isRunning()) {
    findProcess->kill(SIGINT); // Default signal doesn't always work
    hasBeenKilled = true;
  }

  setFocus();
}


kfind'Kfind::newSearch() (./kdeutils/kfind/kfind.cpp:136)

void Kfind::newSearch() {

  stopSearch();

  tabWidget->setDefaults();

  emit haveResults(false);
  emit resultSelected(false);

  setExpanded(false);
  setFocus();
}


kfind'Kfind::handleStdout() (./kdeutils/kfind/kfind.cpp:149)

void Kfind::handleStdout(KProcess *, char *buffer, int buflen) {

  // If find process has been stopped by user ignore rest of the input
  if(hasBeenKilled)
    return;

  // copy data to I/O buffer
  int len = strlen(iBuffer);
  memcpy(iBuffer + len, buffer, buflen);
  iBuffer[len + buflen] = 0;

  // split buffer: too expensive, improve
  char *p;
  while(( p = strchr(iBuffer, '\n')) != 0) {
    *p = 0;

    // found one file, append it to listbox
    win->insertItem(iBuffer);
    if(!isResultReported) {
      emit haveResults(true);
      isResultReported = true;
    }
    memmove(iBuffer, p+1, strlen(p + 1)+1);
  }

  // Update count
  QString str;
  int count = win->childCount();
  if (count == 1) str = i18n("1 file found");
  else str = i18n("%1 files found").arg(KGlobal::locale()->formatNumber(count, 0));

  emit statusChanged(str);
}


kfind'Kfind::setExpanded() (./kdeutils/kfind/kfind.cpp:183)

void Kfind::setExpanded(bool expand) {

  // Changing size "hides" the file table (win) when we do not need it.
  // If we really win->show()/hide() it, tabWidget is not stretched
  // when win is hided. (Bug in QT?)

  if(expand) {
    setMinimumSize(tabWidget->sizeHint().width(),
		   2*tabWidget->sizeHint().height());
    setMaximumHeight(5000);
  }
  else {
    setMinimumSize(tabWidget->sizeHint());
    setMaximumHeight(tabWidget->sizeHint().height());
  }

  emit enableStatusBar(expand);
}


kfind'Kfind::copySelection() (./kdeutils/kfind/kfind.cpp:202)

void Kfind::copySelection() {
  win->copySelection();
}


kfind'Kfind::keyReleaseEvent() (./kdeutils/kfind/kfind.cpp:206)

void Kfind::keyReleaseEvent(QKeyEvent *e)
{
  if (e->key()==Key_Escape)
    stopSearch();

  QWidget::keyReleaseEvent(e);
}