Switch to unified view

a/src/qtgui/fragbuts.cpp b/src/qtgui/fragbuts.cpp
...
...
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
17
18
#include "autoconfig.h"
18
#include "autoconfig.h"
19
19
20
#include <sys/stat.h>
21
20
#include <string>
22
#include <string>
21
#include <vector>
23
#include <vector>
22
24
23
#include <QtGui/QHBoxLayout>
25
#include <QtGui/QHBoxLayout>
24
#include <QtGui/QVBoxLayout>
26
#include <QtGui/QVBoxLayout>
...
...
57
    {
59
    {
58
    currentText += str;
60
    currentText += str;
59
    return true;
61
    return true;
60
    }
62
    }
61
63
64
    bool error(const QXmlParseException& exception) {
65
        fatalError(exception);
66
        return false;
67
    }
68
    bool fatalError(const QXmlParseException& x) {
69
        errorMessage = QString("%2 at line %3 column %4")
70
            .arg(x.message())
71
            .arg(x.lineNumber())
72
            .arg(x.columnNumber());
73
        return false;
74
    }
75
76
    QString errorMessage;
62
private:
77
private:
63
    QWidget *parent;
78
    QWidget *parent;
64
    QVBoxLayout *vlw;
79
    QVBoxLayout *vlw;
65
    QVBoxLayout *vl;
80
    QVBoxLayout *vl;
66
    vector<FragButs::ButFrag>& buttons;
81
    vector<FragButs::ButFrag>& buttons;
...
...
125
    }
140
    }
126
    return true;
141
    return true;
127
}
142
}
128
143
129
FragButs::FragButs(QWidget* parent)
144
FragButs::FragButs(QWidget* parent)
130
    : QWidget(parent), m_ok(false)
145
    : QWidget(parent), m_reftime(0), m_ok(false)
131
{
146
{
132
    string conf = path_cat(theconfig->getConfDir(), "fragbuts.xml");
147
    m_fn = path_cat(theconfig->getConfDir(), "fragbuts.xml");
133
148
134
    string data, reason;
149
    string data, reason;
135
    if (!file_to_string(conf, data, &reason)) {
150
    if (!file_to_string(m_fn, data, &reason)) {
136
    QMessageBox::warning(0, "Recoll", 
151
    QMessageBox::warning(0, "Recoll", 
137
                 tr("%1 not found.").arg(
152
                 tr("%1 not found.").arg(
138
                                 QString::fromLocal8Bit(conf.c_str())));
153
                                 QString::fromLocal8Bit(m_fn.c_str())));
139
        LOGERR(("Fragbuts:: can't read [%s]\n", conf.c_str()));
154
        LOGERR(("Fragbuts:: can't read [%s]\n", m_fn.c_str()));
140
        return;
155
        return;
141
    }
156
    }
142
143
    FragButsParser parser(this, m_buttons);
157
    FragButsParser parser(this, m_buttons);
144
    QXmlSimpleReader reader;
158
    QXmlSimpleReader reader;
145
    reader.setContentHandler(&parser);
159
    reader.setContentHandler(&parser);
146
    reader.setErrorHandler(&parser);
160
    reader.setErrorHandler(&parser);
147
    QXmlInputSource xmlInputSource;
161
    QXmlInputSource xmlInputSource;
148
    xmlInputSource.setData(QString::fromUtf8(data.c_str()));
162
    xmlInputSource.setData(QString::fromUtf8(data.c_str()));
149
    if (!reader.parse(xmlInputSource)) {
163
    if (!reader.parse(xmlInputSource)) {
150
    QMessageBox::warning(0, "Recoll", 
164
    QMessageBox::warning(0, "Recoll", tr("%1:\n %2")
151
               tr("%1 could not be parsed.").arg(
152
                                 QString::fromLocal8Bit(conf.c_str())));
165
                             .arg(QString::fromLocal8Bit(m_fn.c_str()))
153
        LOGERR(("FragButs:: parse failed for [%s]\n", conf.c_str()));
166
                             .arg(parser.errorMessage));
154
        return;
167
        return;
155
    }
168
    }
156
    for (vector<ButFrag>::iterator it = m_buttons.begin(); 
169
    for (vector<ButFrag>::iterator it = m_buttons.begin(); 
157
         it != m_buttons.end(); it++) {
170
         it != m_buttons.end(); it++) {
158
        connect(it->button, SIGNAL(clicked(bool)), 
171
        connect(it->button, SIGNAL(clicked(bool)), 
159
                this, SLOT(onButtonClicked(bool)));
172
                this, SLOT(onButtonClicked(bool)));
160
    }
173
    }
161
    setWindowTitle(tr("Fragment Buttons"));
174
    setWindowTitle(tr("Fragment Buttons"));
175
    isStale(&m_reftime);
162
    m_ok = true;
176
    m_ok = true;
163
}
177
}
164
178
165
FragButs::~FragButs()
179
FragButs::~FragButs()
166
{
180
{
181
}
182
183
bool FragButs::isStale(time_t *reftime)
184
{
185
    struct stat st;
186
    stat(m_fn.c_str(), &st);
187
    bool ret = st.st_mtime != m_reftime;
188
    if (reftime)
189
        *reftime = st.st_mtime;
190
    return ret;
167
}
191
}
168
192
169
void FragButs::onButtonClicked(bool on)
193
void FragButs::onButtonClicked(bool on)
170
{
194
{
171
    LOGDEB(("FragButs::onButtonClicked: [%d]\n", int(on)));
195
    LOGDEB(("FragButs::onButtonClicked: [%d]\n", int(on)));