File: scandialog.cpp

package info (click to toggle)
texmaker 4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 42,664 kB
  • ctags: 7,065
  • sloc: cpp: 59,080; ansic: 4,120; xml: 1,660; sh: 59; makefile: 23
file content (116 lines) | stat: -rw-r--r-- 3,857 bytes parent folder | download | duplicates (2)
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
/***************************************************************************
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/
#include <QtGui>
#include <QFileDialog>
#include "scandialog.h"


ScanDialog::ScanDialog(QWidget *parent, const char *name)
    : QDialog( parent)
{
setWindowTitle(name);
setModal(false);
ui.setupUi(this);
scanthread=new Scanner(this);
connect(ui.pushButtonBrowse, SIGNAL(clicked()), this, SLOT(browse()));
connect(ui.pushButtonFind, SIGNAL(clicked()), this, SLOT(find()));
connect(ui.pushButtonAbort, SIGNAL(clicked()), this, SLOT(abort()));
connect(scanthread, SIGNAL(finished()), this, SLOT(showResults()));
connect(scanthread, SIGNAL(fileCountChanged(int)), this, SLOT(setFileCount(int)));
ui.pushButtonAbort->setEnabled(false);
connect(ui.treeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)), this, SLOT(ClickedOnResult(QTreeWidgetItem*,int)));
}
ScanDialog::~ScanDialog()
{
if (scanthread) 
  {
  scanthread->stop();
  scanthread->wait();
  }
}

void ScanDialog::browse()
{
    QString directory = QFileDialog::getExistingDirectory(this,tr("Find"), QDir::currentPath());
    if (!directory.isEmpty()) ui.lineEditDir->setText(directory);
}

void ScanDialog::find()
{
ui.treeWidget->clear();
ui.labelStat->setText(QString("%1 Files").arg(0));
if ((ui.lineEditSearch->text().isEmpty()) || (ui.lineEditDir->text().isEmpty()) ) return;
ui.labelStat->setText("");
ui.pushButtonBrowse->setEnabled(false);  
ui.pushButtonFind->setEnabled(false);
ui.checkBoxSub->setEnabled(false);
ui.lineEditSearch->setEnabled(false);

scanthread->setDir(QDir(ui.lineEditDir->text()));
scanthread->setText(ui.lineEditSearch->text());
scanthread->setRecursive(ui.checkBoxSub->isChecked());
ui.pushButtonAbort->setEnabled(true);
scanthread->start();
}

void ScanDialog::abort()
{
scanthread->stop();
scanthread->wait();
ui.pushButtonBrowse->setEnabled(true);  
ui.pushButtonFind->setEnabled(true);
ui.checkBoxSub->setEnabled(true);
ui.lineEditSearch->setEnabled(true);
}

void ScanDialog::showResults()
{
QStringList fileList, numlineList, lines;
fileList=scanthread->files();
numlineList=scanthread->lines();
for (int i = 0; i < fileList.count(); ++i) 
  {
    
    QTreeWidgetItem *fileNameItem = new QTreeWidgetItem(ui.treeWidget);
    fileNameItem->setData(0,Qt::UserRole,fileList.at(i));
    fileNameItem->setText(0,QFileInfo(fileList.at(i)).fileName());
    lines=numlineList.at(i).split(",");
    for (int j = 0; j < lines.count(); ++j) 
      {
      QTreeWidgetItem *lineItem = new QTreeWidgetItem(fileNameItem);
      lineItem->setText(0,"line "+lines.at(j));
      lineItem->setData(0,Qt::UserRole,fileList.at(i));
      }
  }
ui.pushButtonBrowse->setEnabled(true);  
ui.pushButtonFind->setEnabled(true);
ui.checkBoxSub->setEnabled(true);
ui.lineEditSearch->setEnabled(true);
ui.pushButtonAbort->setEnabled(false);

}

void ScanDialog::setFileCount(int cnt)
{
  ui.labelStat->setText(QString("%1 Files").arg(cnt));
}

void ScanDialog::ClickedOnResult(QTreeWidgetItem* item,int c)
{
if (item) 
  {
  QString dest=item->data(0,Qt::UserRole).toString();
  QString s=item->text(0);
  int l=0;
  if (s.contains("line ")) l=s.remove("line ").toInt();
  emit openFileAtLine(dest,l,true);
  }
}