Switch to unified view

a/src/qtgui/viewaction_w.cpp b/src/qtgui/viewaction_w.cpp
...
...
24
using namespace std;
24
using namespace std;
25
25
26
#include <qpushbutton.h>
26
#include <qpushbutton.h>
27
#include <qtimer.h>
27
#include <qtimer.h>
28
28
29
#if (QT_VERSION < 0x040000)
30
#include <qlistview.h>
29
#include <qlistwidget.h>
31
#define QLVEXACTMATCH Qt::ExactMatch
32
#else
33
#include <q3listview.h>
34
#define QListView Q3ListView
35
#define QListViewItem Q3ListViewItem
36
#define QListViewItemIterator Q3ListViewItemIterator
37
#define QLVEXACTMATCH Q3ListView::ExactMatch
38
#endif
39
30
40
#include <qmessagebox.h>
31
#include <qmessagebox.h>
41
#include <qinputdialog.h>
32
#include <qinputdialog.h>
42
#include <qlayout.h>
33
#include <qlayout.h>
43
34
...
...
48
#include "viewaction_w.h"
39
#include "viewaction_w.h"
49
40
50
void ViewAction::init()
41
void ViewAction::init()
51
{
42
{
52
    connect(closePB, SIGNAL(clicked()), this, SLOT(close()));
43
    connect(closePB, SIGNAL(clicked()), this, SLOT(close()));
53
    connect(chgActPB, SIGNAL(clicked()), this, SLOT(editAction()));
44
    connect(chgActPB, SIGNAL(clicked()), 
54
    connect(actionsLV,
55
#if (QT_VERSION < 0x040000)
56
     SIGNAL(doubleClicked(QListViewItem *, const QPoint &, int)),
57
#else
58
     SIGNAL(doubleClicked(Q3ListViewItem *, const QPoint &, int)),
59
#endif
60
       this, SLOT(editAction()));
45
        this, SLOT(editActions()));
46
    connect(actionsLV,SIGNAL(itemDoubleClicked(QTableWidgetItem *)),
47
      this, SLOT(onItemDoubleClicked(QTableWidgetItem *)));
61
    fillLists();
48
    fillLists();
62
    resize(QSize(640, 250).expandedTo(minimumSizeHint()) );
49
    resize(QSize(640, 250).expandedTo(minimumSizeHint()));
63
}
50
}
64
51
65
void ViewAction::fillLists()
52
void ViewAction::fillLists()
66
{
53
{
67
    actionsLV->clear();
54
    actionsLV->clear();
55
    actionsLV->verticalHeader()->setDefaultSectionSize(20); 
68
    vector<pair<string, string> > defs;
56
    vector<pair<string, string> > defs;
69
    rclconfig->getMimeViewerDefs(defs);
57
    rclconfig->getMimeViewerDefs(defs);
58
    actionsLV->setRowCount(defs.size());
59
    int row = 0;
70
    for (vector<pair<string, string> >::const_iterator it = defs.begin();
60
    for (vector<pair<string, string> >::const_iterator it = defs.begin();
71
     it != defs.end(); it++) {
61
     it != defs.end(); it++) {
72
  new QListViewItem(actionsLV, 
62
  actionsLV->setItem(row, 0, 
73
            QString::fromAscii(it->first.c_str()),
63
     new QTableWidgetItem(QString::fromAscii(it->first.c_str())));
74
            QString::fromAscii(it->second.c_str()));
64
  actionsLV->setItem(row, 1, 
65
     new QTableWidgetItem(QString::fromAscii(it->second.c_str())));
66
  row++;
75
    }
67
    }
76
68
    QStringList labels(tr("Mime type"));
69
    labels.push_back(tr("Command"));
70
    actionsLV->setHorizontalHeaderLabels(labels);
77
}
71
}
78
72
79
void ViewAction::selectMT(const QString& mt)
73
void ViewAction::selectMT(const QString& mt)
80
{
74
{
81
    QListViewItem *item =  actionsLV->findItem(mt, 0, QLVEXACTMATCH);
75
    actionsLV->clearSelection();
82
    if (item) {
76
    QList<QTableWidgetItem *>items = 
83
  actionsLV->ensureItemVisible(item);
77
  actionsLV->findItems(mt, Qt::MatchFixedString|Qt::MatchCaseSensitive);
84
  actionsLV->setSelected(item, true);
78
    for (QList<QTableWidgetItem *>::iterator it = items.begin();
85
  actionsLV->setSelectionAnchor(item);
79
   it != items.end(); it++) {
80
  (*it)->setSelected(true);
81
  actionsLV->setCurrentItem(*it, QItemSelectionModel::Columns);
86
    }
82
    }
87
}
83
}
88
84
void ViewAction::onItemDoubleClicked(QTableWidgetItem * item)
89
// To avoid modifying the listview state from the dbl click signal, as
90
// advised by the manual
91
void ViewAction::listDblClicked()
92
{
85
{
93
    QTimer::singleShot(0, this, SLOT(editAction()));
86
    actionsLV->clearSelection();
87
    item->setSelected(true);
88
    QTableWidgetItem *item0 = actionsLV->item(item->row(), 0);
89
    item0->setSelected(true);
90
    editActions();
94
}
91
}
95
92
96
void ViewAction::editAction()
93
void ViewAction::editActions()
97
{
94
{
98
    QString action0;
95
    QString action0;
99
    list<string> mtypes;
96
    list<string> mtypes;
100
    bool dowarnmultiple = true;
97
    bool dowarnmultiple = true;
101
98
    for (int row = 0; row < actionsLV->rowCount(); row++) {
102
    QListViewItemIterator it(actionsLV);
99
  QTableWidgetItem *item0 = actionsLV->item(row, 0);
103
    while (it.current()) {
104
  QListViewItem *item = it.current();
105
    if (!item->isSelected()) {
100
    if (!item0->isSelected())
106
      ++it;
107
        continue;
101
        continue;
108
  }
109
    mtypes.push_back((const char *)item->text(0).utf8());
102
    mtypes.push_back((const char *)item0->text().local8Bit());
110
  QString action = (const char *)item->text(1).utf8();
103
  QTableWidgetItem *item1 = actionsLV->item(row, 1);
104
  QString action = item1->text();
111
    if (action0.isEmpty()) {
105
    if (action0.isEmpty()) {
112
        action0 = action;
106
        action0 = action;
113
    } else {
107
    } else {
114
        if (action != action0 && dowarnmultiple) {
108
        if (action != action0 && dowarnmultiple) {
115
        switch (QMessageBox::warning(0, "Recoll",
109
        switch (QMessageBox::warning(0, "Recoll",
116
                         tr("Changing actions with different "
110
                         tr("Changing actions with "
117
                        "current values"),
111
                        "different current values"),
118
                         "Continue",
112
                         "Continue",
119
                         "Cancel",
113
                         "Cancel",
120
                         0, 0, 1)) {
114
                         0, 0, 1)) {
121
        case 0: dowarnmultiple = false;break;
115
        case 0: dowarnmultiple = false;break;
122
        case 1: return;
116
        case 1: return;
123
        }
117
        }
124
        }
118
        }
125
    }
119
    }
126
  ++it;
127
    }
120
    }
128
    if (action0.isEmpty())
121
    if (action0.isEmpty())
129
    return;
122
    return;
130
123
131
    bool ok;
124
    bool ok;
132
    QString text = QInputDialog::getText(
125
    QString newaction = QInputDialog::getText("Recoll", "Edit action:", 
133
                   "Recoll", "Edit action:", 
134
                     QLineEdit::Normal,
126
                     QLineEdit::Normal,
135
                     action0, &ok, this);
127
                     action0, &ok, this);
136
    if (!ok || text.isEmpty() ) 
128
    if (!ok || newaction.isEmpty() ) 
137
    return;
129
    return;
138
130
139
    string sact = (const char *)text.utf8();
131
    string sact = (const char *)newaction.local8Bit();
140
    for (list<string>::const_iterator it = mtypes.begin(); 
132
    for (list<string>::const_iterator it = mtypes.begin(); 
141
     it != mtypes.end(); it++) {
133
     it != mtypes.end(); it++) {
142
    rclconfig->setMimeViewerDef(*it, sact);
134
    rclconfig->setMimeViewerDef(*it, sact);
143
    }
135
    }
144
    fillLists();
136
    fillLists();