|
a/src/qtgui/viewaction_w.cpp |
|
b/src/qtgui/viewaction_w.cpp |
|
... |
|
... |
12 |
* You should have received a copy of the GNU General Public License
|
12 |
* You should have received a copy of the GNU General Public License
|
13 |
* along with this program; if not, write to the
|
13 |
* along with this program; if not, write to the
|
14 |
* Free Software Foundation, Inc.,
|
14 |
* Free Software Foundation, Inc.,
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
16 |
*/
|
16 |
*/
|
|
|
17 |
|
|
|
18 |
#include <stdio.h>
|
|
|
19 |
|
17 |
#include <vector>
|
20 |
#include <vector>
|
18 |
#include <utility>
|
21 |
#include <utility>
|
19 |
#include <string>
|
22 |
#include <string>
|
20 |
|
23 |
|
21 |
using namespace std;
|
24 |
using namespace std;
|
|
... |
|
... |
36 |
#include "viewaction_w.h"
|
39 |
#include "viewaction_w.h"
|
37 |
|
40 |
|
38 |
void ViewAction::init()
|
41 |
void ViewAction::init()
|
39 |
{
|
42 |
{
|
40 |
connect(closePB, SIGNAL(clicked()), this, SLOT(close()));
|
43 |
connect(closePB, SIGNAL(clicked()), this, SLOT(close()));
|
41 |
connect(chgActPB, SIGNAL(clicked()),
|
44 |
connect(chgActPB, SIGNAL(clicked()), this, SLOT(editActions()));
|
42 |
this, SLOT(editActions()));
|
|
|
43 |
connect(actionsLV,SIGNAL(itemDoubleClicked(QTableWidgetItem *)),
|
45 |
connect(actionsLV,SIGNAL(itemDoubleClicked(QTableWidgetItem *)),
|
44 |
this, SLOT(onItemDoubleClicked(QTableWidgetItem *)));
|
46 |
this, SLOT(onItemDoubleClicked(QTableWidgetItem *)));
|
|
|
47 |
useDesktopCB->setChecked(prefs.useDesktopOpen);
|
|
|
48 |
onUseDesktopCBToggled(prefs.useDesktopOpen);
|
|
|
49 |
connect(useDesktopCB, SIGNAL(stateChanged(int)),
|
|
|
50 |
this, SLOT(onUseDesktopCBToggled(int)));
|
|
|
51 |
connect(setExceptCB, SIGNAL(stateChanged(int)),
|
|
|
52 |
this, SLOT(onSetExceptCBToggled(int)));
|
|
|
53 |
resize(QSize(640, 480).expandedTo(minimumSizeHint()));
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
void ViewAction::onUseDesktopCBToggled(int onoff)
|
|
|
57 |
{
|
|
|
58 |
prefs.useDesktopOpen = onoff != 0;
|
45 |
fillLists();
|
59 |
fillLists();
|
46 |
resize(QSize(640, 250).expandedTo(minimumSizeHint()));
|
60 |
setExceptCB->setEnabled(prefs.useDesktopOpen);
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
void ViewAction::onSetExceptCBToggled(int onoff)
|
|
|
64 |
{
|
|
|
65 |
newActionLE->setEnabled(onoff != 0);
|
47 |
}
|
66 |
}
|
48 |
|
67 |
|
49 |
void ViewAction::fillLists()
|
68 |
void ViewAction::fillLists()
|
50 |
{
|
69 |
{
|
51 |
actionsLV->clear();
|
70 |
actionsLV->clear();
|
52 |
actionsLV->verticalHeader()->setDefaultSectionSize(20);
|
71 |
actionsLV->verticalHeader()->setDefaultSectionSize(20);
|
53 |
vector<pair<string, string> > defs;
|
72 |
vector<pair<string, string> > defs;
|
54 |
theconfig->getMimeViewerDefs(defs);
|
73 |
theconfig->getMimeViewerDefs(defs);
|
55 |
actionsLV->setRowCount(defs.size());
|
74 |
actionsLV->setRowCount(defs.size());
|
56 |
int row = 0;
|
75 |
int row = 0;
|
|
|
76 |
|
|
|
77 |
set<string> viewerXs;
|
|
|
78 |
if (prefs.useDesktopOpen) {
|
|
|
79 |
string s = theconfig->getMimeViewerAllEx();
|
|
|
80 |
stringToStrings(s, viewerXs);
|
|
|
81 |
}
|
57 |
for (vector<pair<string, string> >::const_iterator it = defs.begin();
|
82 |
for (vector<pair<string, string> >::const_iterator it = defs.begin();
|
58 |
it != defs.end(); it++) {
|
83 |
it != defs.end(); it++) {
|
59 |
actionsLV->setItem(row, 0,
|
84 |
actionsLV->setItem(row, 0,
|
60 |
new QTableWidgetItem(QString::fromAscii(it->first.c_str())));
|
85 |
new QTableWidgetItem(QString::fromAscii(it->first.c_str())));
|
|
|
86 |
if (!prefs.useDesktopOpen ||
|
|
|
87 |
viewerXs.find(it->first) != viewerXs.end()) {
|
61 |
actionsLV->setItem(row, 1,
|
88 |
actionsLV->setItem(
|
|
|
89 |
row, 1,
|
62 |
new QTableWidgetItem(QString::fromAscii(it->second.c_str())));
|
90 |
new QTableWidgetItem(QString::fromAscii(it->second.c_str())));
|
|
|
91 |
} else {
|
|
|
92 |
actionsLV->setItem(
|
|
|
93 |
row, 1, new QTableWidgetItem(tr("Desktop Default")));
|
|
|
94 |
}
|
63 |
row++;
|
95 |
row++;
|
64 |
}
|
96 |
}
|
65 |
QStringList labels(tr("MIME type"));
|
97 |
QStringList labels(tr("MIME type"));
|
66 |
labels.push_back(tr("Command"));
|
98 |
labels.push_back(tr("Command"));
|
67 |
actionsLV->setHorizontalHeaderLabels(labels);
|
99 |
actionsLV->setHorizontalHeaderLabels(labels);
|
|
... |
|
... |
76 |
it != items.end(); it++) {
|
108 |
it != items.end(); it++) {
|
77 |
(*it)->setSelected(true);
|
109 |
(*it)->setSelected(true);
|
78 |
actionsLV->setCurrentItem(*it, QItemSelectionModel::Columns);
|
110 |
actionsLV->setCurrentItem(*it, QItemSelectionModel::Columns);
|
79 |
}
|
111 |
}
|
80 |
}
|
112 |
}
|
|
|
113 |
|
81 |
void ViewAction::onItemDoubleClicked(QTableWidgetItem * item)
|
114 |
void ViewAction::onItemDoubleClicked(QTableWidgetItem * item)
|
82 |
{
|
115 |
{
|
83 |
actionsLV->clearSelection();
|
116 |
actionsLV->clearSelection();
|
84 |
item->setSelected(true);
|
117 |
item->setSelected(true);
|
85 |
QTableWidgetItem *item0 = actionsLV->item(item->row(), 0);
|
118 |
QTableWidgetItem *item0 = actionsLV->item(item->row(), 0);
|
|
... |
|
... |
88 |
}
|
121 |
}
|
89 |
|
122 |
|
90 |
void ViewAction::editActions()
|
123 |
void ViewAction::editActions()
|
91 |
{
|
124 |
{
|
92 |
QString action0;
|
125 |
QString action0;
|
|
|
126 |
int except0 = -1;
|
|
|
127 |
|
|
|
128 |
set<string> viewerXs;
|
|
|
129 |
string s = theconfig->getMimeViewerAllEx();
|
|
|
130 |
stringToStrings(s, viewerXs);
|
|
|
131 |
|
93 |
list<string> mtypes;
|
132 |
list<string> mtypes;
|
94 |
bool dowarnmultiple = true;
|
133 |
bool dowarnmultiple = true;
|
95 |
for (int row = 0; row < actionsLV->rowCount(); row++) {
|
134 |
for (int row = 0; row < actionsLV->rowCount(); row++) {
|
96 |
QTableWidgetItem *item0 = actionsLV->item(row, 0);
|
135 |
QTableWidgetItem *item0 = actionsLV->item(row, 0);
|
97 |
if (!item0->isSelected())
|
136 |
if (!item0->isSelected())
|
98 |
continue;
|
137 |
continue;
|
99 |
mtypes.push_back((const char *)item0->text().toLocal8Bit());
|
138 |
string mtype = (const char *)item0->text().toLocal8Bit();
|
|
|
139 |
mtypes.push_back(mtype);
|
100 |
QTableWidgetItem *item1 = actionsLV->item(row, 1);
|
140 |
QTableWidgetItem *item1 = actionsLV->item(row, 1);
|
101 |
QString action = item1->text();
|
141 |
QString action = item1->text();
|
|
|
142 |
int except = viewerXs.find(mtype) != viewerXs.end();
|
102 |
if (action0.isEmpty()) {
|
143 |
if (action0.isEmpty()) {
|
103 |
action0 = action;
|
144 |
action0 = action;
|
|
|
145 |
except0 = except;
|
104 |
} else {
|
146 |
} else {
|
105 |
if (action != action0 && dowarnmultiple) {
|
147 |
if ((action != action0 || except != except0) && dowarnmultiple) {
|
106 |
switch (QMessageBox::warning(0, "Recoll",
|
148 |
switch (QMessageBox::warning(0, "Recoll",
|
107 |
tr("Changing actions with "
|
149 |
tr("Changing entries with "
|
108 |
"different current values"),
|
150 |
"different current values"),
|
109 |
"Continue",
|
151 |
"Continue",
|
110 |
"Cancel",
|
152 |
"Cancel",
|
111 |
0, 0, 1)) {
|
153 |
0, 0, 1)) {
|
112 |
case 0: dowarnmultiple = false;break;
|
154 |
case 0: dowarnmultiple = false;break;
|
|
... |
|
... |
116 |
}
|
158 |
}
|
117 |
}
|
159 |
}
|
118 |
if (action0.isEmpty())
|
160 |
if (action0.isEmpty())
|
119 |
return;
|
161 |
return;
|
120 |
|
162 |
|
121 |
bool ok;
|
163 |
string sact = (const char *)newActionLE->text().toLocal8Bit();
|
122 |
QString newaction = QInputDialog::getText(this, "Recoll", "Edit action:",
|
164 |
trimstring(sact);
|
123 |
QLineEdit::Normal,
|
165 |
for (list<string>::const_iterator mit = mtypes.begin();
|
124 |
action0, &ok);
|
166 |
mit != mtypes.end(); mit++) {
|
125 |
if (!ok || newaction.isEmpty() )
|
167 |
set<string>::iterator xit = viewerXs.find(*mit);
|
126 |
return;
|
168 |
if (setExceptCB->isChecked()) {
|
|
|
169 |
if (xit == viewerXs.end()) {
|
|
|
170 |
viewerXs.insert(*mit);
|
|
|
171 |
}
|
|
|
172 |
} else {
|
|
|
173 |
if (xit != viewerXs.end()) {
|
|
|
174 |
viewerXs.erase(xit);
|
|
|
175 |
}
|
|
|
176 |
}
|
|
|
177 |
// An empty action will restore the default (erase from
|
|
|
178 |
// topmost conftree)
|
|
|
179 |
theconfig->setMimeViewerDef(*mit, sact);
|
|
|
180 |
}
|
127 |
|
181 |
|
128 |
string sact = (const char *)newaction.toLocal8Bit();
|
182 |
s = stringsToString(viewerXs);
|
129 |
for (list<string>::const_iterator it = mtypes.begin();
|
183 |
theconfig->setMimeViewerAllEx(s);
|
130 |
it != mtypes.end(); it++) {
|
|
|
131 |
theconfig->setMimeViewerDef(*it, sact);
|
|
|
132 |
}
|
|
|
133 |
fillLists();
|
184 |
fillLists();
|
134 |
}
|
185 |
}
|