~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to kexi/core/kexiuseraction.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <KActionCollection>
 
2
#include <kmessagebox.h>
 
3
#include <kdebug.h>
 
4
#include <kshortcut.h>
 
5
 
 
6
#include <kexidb/cursor.h>
 
7
 
 
8
#include "kexipart.h"
 
9
#include "kexipartmanager.h"
 
10
 
 
11
#include "kexiproject.h"
 
12
#include "keximainwindow.h"
 
13
#include "kexiuseraction.h"
 
14
 
 
15
KexiUserAction::KexiUserAction(KActionCollection *parent, const QString &name, const QString &text, const QString &pixmap)
 
16
        : KAction(KIcon(pixmap), text, parent)
 
17
{
 
18
    setObjectName(name);
 
19
    m_method = 0;
 
20
    connect(this, SIGNAL(triggered()), this, SLOT(execute()));
 
21
}
 
22
 
 
23
void
 
24
KexiUserAction::setMethod(int method, Arguments args)
 
25
{
 
26
    m_method = method;
 
27
    m_args = args;
 
28
}
 
29
 
 
30
void
 
31
KexiUserAction::execute()
 
32
{
 
33
    kDebug() << "KexiUserAction::execute(): " << KexiUserActionMethod::methodName(m_method);
 
34
 
 
35
    switch (m_method) {
 
36
    case OpenObject: { //open a project object
 
37
        //get partinfo
 
38
        KexiPart::Info *i = Kexi::partManager().infoForMimeType(m_args[0].toString().toLatin1());
 
39
        if (!i) {
 
40
            KMessageBox::error(KexiMainWindow::global()->thisWidget(), i18n("Specified part does not exist"));
 
41
            return;
 
42
        }
 
43
 
 
44
        Kexi::partManager().part(i); //load part if doesn't exists
 
45
        KexiPart::Item *item = KexiMainWindow::global()->project()->item(i, m_args[1].toString());
 
46
        bool openingCancelled;
 
47
        if (!KexiMainWindow::global()->openObject(item, Kexi::DataViewMode, openingCancelled)
 
48
                && !openingCancelled) {
 
49
            KMessageBox::error(KexiMainWindow::global()->thisWidget(), i18n("Specified document could not be opened."));
 
50
            return;
 
51
        }
 
52
        if (openingCancelled)
 
53
            return;
 
54
        break;
 
55
    }
 
56
    default:
 
57
        break;
 
58
    }
 
59
}
 
60
 
 
61
KexiUserAction *
 
62
KexiUserAction::fromCurrentRecord(KActionCollection *parent, KexiDB::Cursor *c)
 
63
{
 
64
    if (!c || c->bof() || c->eof())
 
65
        return 0;
 
66
 
 
67
    KexiUserAction *a = new KexiUserAction(parent,
 
68
                                           c->value(1).toString(), c->value(2).toString(), c->value(3).toString());
 
69
    QString args = c->value(5).toString();
 
70
    bool quote = false;
 
71
 
 
72
    Arguments arg;
 
73
    QString tmp;
 
74
    const int len = args.length();
 
75
    for (int i = 0; i < len; i++) {
 
76
        if (args[i] == '"') { // if current char is quoted unqote or other way round
 
77
            quote = !quote;
 
78
        } else if (args[i] == ',' && !quote) { //if item end add tmp to argumentstack and strip quotes if nessesery
 
79
            if (tmp.left(1) == "\"" && tmp.right(1) == "\"")
 
80
                tmp = tmp.mid(1, tmp.length() - 2);
 
81
 
 
82
            arg.append(QVariant(tmp));
 
83
            tmp = "";
 
84
        } else { //else simply add char to tmp
 
85
            tmp += args[i];
 
86
        }
 
87
    }
 
88
 
 
89
    if (tmp.left(1) == "\"" && tmp.right(1) == "\"")
 
90
        tmp = tmp.mid(1, tmp.length() - 2);
 
91
 
 
92
    arg.append(QVariant(tmp));
 
93
 
 
94
    a->setMethod(c->value(4).toInt(), arg);
 
95
    return a;
 
96
}
 
97
 
 
98
KexiUserAction::~KexiUserAction()
 
99
{
 
100
}
 
101
 
 
102
#include "kexiuseraction.moc"
 
103