1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
/***************************************************************************
* copyright : (C) 2003-2011 by Pascal Brachet *
* http://www.xm1math.net/texmaker/ *
* *
* 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. *
* *
***************************************************************************/
#ifndef SCANDIALOG_H
#define SCANDIALOG_H
#include <QThread>
#include <QDirIterator>
#include <QFileInfo>
#include <QTextStream>
#include <QDebug>
#include "ui_scandialog.h"
class Scanner : public QThread
{
Q_OBJECT
public:
explicit Scanner(QObject *parent = 0)
: QThread(parent), stopped(false)
{
}
void run()
{
fileList.clear();
numlineList.clear();
QStringList extensions;
extensions << "tex" << "bib" << "sty" << "cls" << "mp" << "Rnw" << "asy";
QStringList listoflines;
QDirIterator iterator(scanDir,isRecursive? QDirIterator::Subdirectories : QDirIterator::NoIteratorFlags);
while(!stopped && iterator.hasNext())
{
QString entry(iterator.next());
if(extensions.contains(QFileInfo(entry).suffix().toLower()))
{
QFile file(entry);
listoflines.clear();
if (file.open(QIODevice::ReadOnly))
{
QString line;
QTextStream in(&file);
int l=0;
while (!in.atEnd())
{
if (stopped) break;
line = in.readLine();
l++;
if (line.contains(text)) listoflines << QString::number(l);
}
}
if (listoflines.count()>0)
{
fileList << entry;
numlineList << listoflines.join(",");
emit fileCountChanged(fileList.count());
}
}
}
quit();
}
void setRecursive(bool rec)
{
isRecursive=rec;
}
void setDir(const QDir &dir)
{
scanDir=dir;
}
void setText(const QString &t)
{
text=t;
}
QStringList files() const
{
return fileList;
}
QStringList lines() const
{
return numlineList;
}
public slots:
void stop()
{
stopped = true;
}
signals:
void fileCountChanged(int);
private:
QStringList fileList, numlineList;
bool stopped;
bool isRecursive;
QDir scanDir;
QString text;
};
class ScanDialog : public QDialog
{
Q_OBJECT
public:
ScanDialog(QWidget *parent = 0, const char *name = 0);
~ScanDialog();
Ui::ScanDialog ui;
private:
Scanner* scanthread;
private slots:
void browse();
void find();
void abort();
void showResults();
void setFileCount(int cnt);
void ClickedOnResult(QTreeWidgetItem* item,int c);
signals:
void openFileAtLine(QString,int,bool);
};
#endif
|