~dandrader/unity8/multiInstanceApp

« back to all changes in this revision

Viewing changes to plugins/Utils/windowstatestorage.cpp

Initial merge from trunk; some tests don't run again yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
QMutex WindowStateStorage::s_mutex;
29
29
 
30
30
inline QString sanitiseString(QString string) {
31
 
    return string.remove("\"").remove("'").remove("\\");
 
31
    return string.remove(QLatin1Char('\"'))
 
32
                 .remove(QLatin1Char('\''))
 
33
                 .remove(QLatin1Char('\\'));
32
34
}
33
35
 
34
36
WindowStateStorage::WindowStateStorage(QObject *parent):
74
76
    return (WindowState)query.value(QStringLiteral("state")).toInt();
75
77
}
76
78
 
77
 
void WindowStateStorage::saveGeometry(const QString &windowId, const QRect rect)
 
79
void WindowStateStorage::saveGeometry(const QString &windowId, const QRect &rect)
78
80
{
79
81
    const QString queryString = QStringLiteral("INSERT OR REPLACE INTO geometry (windowId, x, y, width, height) values ('%1', '%2', '%3', '%4', '%5');")
80
82
            .arg(sanitiseString(windowId))
90
92
{
91
93
    const QString queryString = QStringLiteral("INSERT OR REPLACE INTO stage (appId, stage) values ('%1', '%2');")
92
94
            .arg(sanitiseString(appId))
93
 
            .arg((int)stage);
 
95
            .arg(stage);
94
96
 
95
97
    saveValue(queryString);
96
98
}
121
123
    }
122
124
}
123
125
 
124
 
QRect WindowStateStorage::getGeometry(const QString &windowId, const QRect defaultValue) const
 
126
QRect WindowStateStorage::getGeometry(const QString &windowId, const QRect &defaultValue) const
125
127
{
126
128
    QString queryString = QStringLiteral("SELECT * FROM geometry WHERE windowId = '%1';")
127
129
            .arg(sanitiseString(windowId));
131
133
    if (!query.first()) {
132
134
        return defaultValue;
133
135
    }
134
 
    return QRect(query.value(QStringLiteral("x")).toInt(), query.value(QStringLiteral("y")).toInt(), query.value(QStringLiteral("width")).toInt(), query.value(QStringLiteral("height")).toInt());
 
136
    return QRect(query.value(QStringLiteral("x")).toInt(), query.value(QStringLiteral("y")).toInt(),
 
137
                 query.value(QStringLiteral("width")).toInt(), query.value(QStringLiteral("height")).toInt());
135
138
}
136
139
 
137
140
void WindowStateStorage::initdb()