Child: [3b18fa] (diff)

Download this file

ptrans_w.cpp    135 lines (114 with data), 3.9 kB

  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
/* Copyright (C) 2006 J.F.Dockes
* 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; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <vector>
#include <utility>
#include <string>
using namespace std;
#include <qpushbutton.h>
#include <qtimer.h>
#include <qlistwidget.h>
#include <qmessagebox.h>
#include <qinputdialog.h>
#include <qlayout.h>
#include "recoll.h"
#include "debuglog.h"
#include "guiutils.h"
#include "conftree.h"
#include "ptrans_w.h"
void EditTrans::init(const string& dbdir)
{
m_dbdir = path_canon(dbdir);
connect(transTW, SIGNAL(itemDoubleClicked(QTableWidgetItem *)),
this, SLOT(onItemDoubleClicked(QTableWidgetItem *)));
connect(cancelPB, SIGNAL(clicked()), this, SLOT(close()));
QString lab = whatIdxLA->text();
lab.append(QString::fromLocal8Bit(m_dbdir.c_str()));
whatIdxLA->setText(lab);
QStringList labels(tr("Source path"));
labels.push_back(tr("Local path"));
transTW->setHorizontalHeaderLabels(labels);
ConfSimple *conftrans = theconfig->getPTrans();
if (!conftrans)
return;
int row = 0;
vector<string> opaths = conftrans->getNames(m_dbdir);
for (vector<string>::const_iterator it = opaths.begin();
it != opaths.end(); it++) {
transTW->setRowCount(row+1);
transTW->setItem(row, 0, new QTableWidgetItem(
QString::fromLocal8Bit(it->c_str())));
string npath;
conftrans->get(*it, npath, m_dbdir);
transTW->setItem(row, 1, new QTableWidgetItem(
QString::fromLocal8Bit(npath.c_str())));
row++;
}
resize(QSize(640, 300).expandedTo(minimumSizeHint()));
}
void EditTrans::onItemDoubleClicked(QTableWidgetItem *item)
{
transTW->editItem(item);
}
void EditTrans::on_savePB_clicked()
{
ConfSimple *conftrans = theconfig->getPTrans();
if (!conftrans) {
QMessageBox::warning(0, "Recoll", tr("Config error"));
return;
}
conftrans->holdWrites(true);
conftrans->eraseKey(m_dbdir);
for (int row = 0; row < transTW->rowCount(); row++) {
QTableWidgetItem *item0 = transTW->item(row, 0);
string from = path_canon((const char *)item0->text().toLocal8Bit());
QTableWidgetItem *item1 = transTW->item(row, 1);
string to = path_canon((const char*)item1->text().toLocal8Bit());
conftrans->set(from, to, m_dbdir);
}
conftrans->holdWrites(false);
close();
}
void EditTrans::on_addPB_clicked()
{
transTW->setRowCount(transTW->rowCount()+1);
int row = transTW->rowCount()-1;
transTW->setItem(row, 0, new QTableWidgetItem(tr("Original path")));
transTW->setItem(row, 1, new QTableWidgetItem(tr("Local path")));
transTW->editItem(transTW->item(row, 0));
}
void EditTrans::on_delPB_clicked()
{
QModelIndexList indexes = transTW->selectionModel()->selectedIndexes();
vector<int> rows;
for (int i = 0; i < indexes.size(); i++) {
rows.push_back(indexes.at(i).row());
}
sort(rows.begin(), rows.end());
rows.resize(unique(rows.begin(), rows.end()) - rows.begin());
for (int i = rows.size()-1; i >= 0; i--) {
transTW->removeRow(rows[i]);
}
}
void EditTrans::on_transTW_itemSelectionChanged()
{
QModelIndexList indexes = transTW->selectionModel()->selectedIndexes();
if(indexes.size() < 1)
delPB->setEnabled(0);
else
delPB->setEnabled(1);
}