Skip to content

Commit 058264e

Browse files
committed
chore: finished
1 parent 98c2ac2 commit 058264e

File tree

5 files changed

+55
-5
lines changed

5 files changed

+55
-5
lines changed

Diff for: qml/MainView.qml

+21-1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ Page {
149149
if (CommandLine.isAuthing) {
150150
return;
151151
}
152+
var currentDesktop = DesktopModel.get(view.currentIndex).name;
153+
if (DesktopConfigModel.dataIsExist(currentDesktop)) {
154+
var envs = DesktopConfigModel.getFromName(currentDesktop).envs;
155+
CommandLine.env = envs;
156+
}
152157
CommandLine.RequestLogin();
153158
}
154159
}
@@ -174,6 +179,11 @@ Page {
174179
if (CommandLine.isAuthing) {
175180
return;
176181
}
182+
var currentDesktop = DesktopModel.get(view.currentIndex).name;
183+
if (DesktopConfigModel.dataIsExist(currentDesktop)) {
184+
var envs = DesktopConfigModel.getFromName(currentDesktop).envs;
185+
CommandLine.env = envs;
186+
}
177187
Settings.setStartSession(DesktopModel.get(view.currentIndex).name);
178188
Settings.setStartUser(user.text);
179189
CommandLine.RequestLogin();
@@ -245,7 +255,17 @@ Page {
245255
id: commandField
246256
placeholderText: "Command"
247257
Layout.alignment: Qt.AlignHCenter
248-
text: CommandLine.command
258+
text: {
259+
var currentDesktop = DesktopModel.get(view.currentIndex).name;
260+
if (!DesktopConfigModel.dataIsExist(currentDesktop)) {
261+
return CommandLine.command;
262+
}
263+
var map = DesktopConfigModel.getFromName(currentDesktop);
264+
if (!map.hasAlias) {
265+
return CommandLine.command;
266+
}
267+
return map.execAlias;
268+
}
249269
onEditingFinished: {
250270
CommandLine.command = commandField.text;
251271
}

Diff for: qml/SettingsItemDelegate.qml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ ItemDelegate {
4040
Layout.fillWidth: true
4141
visible: model.hasAlias
4242
text: model.execAlias
43-
onEditingFinished: {
43+
onAccepted: {
4444
model.execAlias = aliasField.text;
4545
}
4646
placeholderText: "ExecAlias"

Diff for: src/CommandLine.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ CommandLine::CommandLine(QObject *parent)
2323
, m_userIcon(QUrl("qrc:/image/account.svg"))
2424
, m_command(QString())
2525
, m_isAuthing(false)
26+
, m_env(QStringList())
2627
{
2728
QSettings setting;
2829
QString user = setting.value("user").toString();
@@ -64,6 +65,13 @@ CommandLine::setCommand(const QString &command)
6465
Q_EMIT commandChanged();
6566
}
6667

68+
void
69+
CommandLine::setEnv(const QStringList &env)
70+
{
71+
m_env = env;
72+
Q_EMIT envChanged();
73+
}
74+
6775
void
6876
CommandLine::connectToGreetd()
6977
{
@@ -137,7 +145,7 @@ CommandLine::handleSuccessed()
137145

138146
request["type"] = "start_session";
139147
request["cmd"] = m_command.split(' ');
140-
request["env"] = QStringList();
148+
request["env"] = m_env;
141149
QJsonDocument json;
142150

143151
json.setObject(QJsonObject::fromVariantMap(request));

Diff for: src/CommandLine.h

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ class CommandLine final : public QObject
4343
inline QString command() { return m_command; }
4444
void setCommand(const QString &command);
4545

46+
Q_PROPERTY(QStringList env READ env WRITE setEnv NOTIFY envChanged)
47+
inline QStringList env() { return m_env; }
48+
void setEnv(const QStringList &env);
49+
4650
Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged)
4751
inline QString errorMessage() { return m_errorMessage; }
4852

@@ -69,6 +73,7 @@ class CommandLine final : public QObject
6973
void userIconChanged();
7074
void commandChanged();
7175
void isAuthingChanged();
76+
void envChanged();
7277

7378
private slots:
7479
void handleDataRead();
@@ -95,4 +100,5 @@ private slots:
95100
QUrl m_userIcon;
96101
QString m_command;
97102
bool m_isAuthing;
103+
QStringList m_env;
98104
};

Diff for: src/DesktopConfigListModel.h

+18-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <QList>
55
#include <QObject>
66
#include <QQmlEngine>
7+
#include <algorithm>
78

89
class DesktopConfigModel final : public QAbstractListModel
910
{
@@ -35,13 +36,28 @@ class DesktopConfigModel final : public QAbstractListModel
3536

3637
Q_INVOKABLE void remove(int row);
3738

39+
Q_INVOKABLE bool dataIsExist(const QString &desktop) const;
40+
41+
Q_INVOKABLE QVariantMap getFromName(const QString &name) const
42+
{
43+
QVariantMap data;
44+
for (int i = 0; i < m_configs.length(); ++i) {
45+
if (m_configs[i].name == name) {
46+
data.insert("name", m_configs[i].name);
47+
data.insert("hasAlias", m_configs[i].hasAlias);
48+
data.insert("execAlias", m_configs[i].execAlias);
49+
data.insert("envs", m_configs[i].envs);
50+
break;
51+
}
52+
}
53+
return data;
54+
}
55+
3856
private:
3957
int rowCount(const QModelIndex & = QModelIndex()) const override;
4058
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
4159
QHash<int, QByteArray> roleNames() const override;
4260

43-
bool dataIsExist(const QString &desktop) const;
44-
4561
void get_file_config();
4662
void save_file_config();
4763

0 commit comments

Comments
 (0)