File: keyboardsql.cpp

package info (click to toggle)
tipp10 3.3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,984 kB
  • sloc: cpp: 8,343; xml: 70; ansic: 60; makefile: 11
file content (131 lines) | stat: -rw-r--r-- 4,757 bytes parent folder | download | duplicates (2)
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
/*
Copyright (c) 2006-2009, Tom Thielicke IT Solutions

SPDX-License-Identifier: GPL-2.0-only
*/

/****************************************************************
**
** Implementation of the KeyboardSql class
** File name: keyboardsql.cpp
**
****************************************************************/

#include <QFile>
#include <QSqlQuery>
#include <QString>
#include <QTextStream>
#include <QVariant>

#include "keyboardsql.h"

KeyboardSql::KeyboardSql(QString keyboardLayout)
    : layout(keyboardLayout)
{
    // Get finger text
    getFingerDescription();
}

void KeyboardSql::getFingerDescription()
{
    fingers << QObject::tr("Left little finger")
            << QObject::tr("Left ring finger")
            << QObject::tr("Left middle finger")
            << QObject::tr("Left forefinger") << QObject::tr("Right forefinger")
            << QObject::tr("Right middle finger")
            << QObject::tr("Right ring finger")
            << QObject::tr("Right little finger") << QObject::tr("Thumb");
}

bool KeyboardSql::getKeyLayout(QChar givenchar, int* left, int* top, int* color,
    int* form, int* modifier, int* modifier2, int* finger, QString* status)
{

    // Convert given char into properties of a key
    QString tableName = "keyboard_grids";

    QSqlQuery query;
    if (query.exec("SELECT " + tableName + ".left, " + tableName + ".top, "
            + tableName + ".color, " + tableName + ".form, "
            + "keyboard_layouts.modifier1, " + "keyboard_layouts.modifier2, "
            + tableName + ".finger " + "FROM keyboard_layouts, " + tableName
            + " " + "WHERE keyboard_layouts.layout = '" + layout + "' " + "AND "
            + tableName + ".layout_country = '" + layout.left(2) + "' " + "AND "
            + tableName + ".key = keyboard_layouts.grid "
            + "AND keyboard_layouts.unicode = "
            + QString::number(givenchar.unicode()) + ";")) {
        if (query.first()) {
            *left = query.value(0).toInt();
            *top = query.value(1).toInt();
            *color = query.value(2).toInt();
            *form = query.value(3).toInt();
            *modifier = query.value(4).toInt();
            *modifier2 = query.value(5).toInt();
            *finger = query.value(6).toInt();
            *status = fingers.at(query.value(6).toInt());
            return true;
        }
    }
    return false;
}

bool KeyboardSql::getModifierLayout(int givenmodifier, int* left, int* top,
    int* color, int* form, int* finger, QString* status)
{

    // Convert given id into properties of a key
    QString tableName = "keyboard_grids";

    QSqlQuery query;
    if (query.exec("SELECT " + tableName + ".left, " + tableName + ".top, "
            + tableName + ".color, " + tableName + ".form, " + tableName
            + ".finger FROM " + tableName + " WHERE " + tableName
            + ".layout_country = '" + layout.left(2) + "' " + "AND " + tableName
            + ".key = " + QString::number(givenmodifier) + ";")) {
        if (query.first()) {
            *left = query.value(0).toInt();
            *top = query.value(1).toInt();
            *color = query.value(2).toInt();
            *form = query.value(3).toInt();
            *finger = query.value(4).toInt();
            status->prepend(fingers.at(query.value(4).toInt()) + " + ");
            return true;
        }
    }
    return false;
}

bool KeyboardSql::getNumLayout(QChar givenchar, int* left, int* top, int* color,
    int* form, int* finger, QString* status)
{

    // Convert given char into properties of a key
    QString tableName = "numboard_grids";

    QSqlQuery query;
    if (query.exec("SELECT " + tableName + ".left, " + tableName
            + ".top, "
              ""
            + tableName + ".color, " + tableName + ".form, " + tableName
            + ".finger "
              "FROM numboard_layouts, "
            + tableName + " " + "WHERE numboard_layouts.layout_country = '"
            + layout.left(2) + "' " + "AND numboard_layouts.layout_os = '"
            + layout.right(3) + "' " + "AND " + tableName
            + ".layout_country = '" + layout.left(2) + "' " + "AND " + tableName
            + ".layout_os = '" + layout.right(3) + "' " + "AND " + tableName
            + ".key = numboard_layouts.grid "
            + "AND numboard_layouts.unicode = "
            + QString::number(givenchar.unicode()) + ";")) {
        if (query.first()) {
            *left = query.value(0).toInt();
            *top = query.value(1).toInt();
            *color = query.value(2).toInt();
            *form = query.value(3).toInt();
            *finger = query.value(4).toInt();
            *status = fingers.at(query.value(4).toInt());
            return true;
        }
    }
    return false;
}