mirror of
https://github.com/ckb-next/ckb-next.git
synced 2026-10-10 12:27:21 -04:00
Merge branch 'cli-switch'
This commit is contained in:
+39
-2
@@ -11,6 +11,7 @@
|
||||
#include "kbprofiledialog.h"
|
||||
#include "ui_kbwidget.h"
|
||||
#include "ui_kblightwidget.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
KbWidget::KbWidget(QWidget *parent, Kb *_device) :
|
||||
QWidget(parent),
|
||||
@@ -29,6 +30,9 @@ KbWidget::KbWidget(QWidget *parent, Kb *_device) :
|
||||
connect(device, SIGNAL(modeRenamed()), this, SLOT(modeChanged()));
|
||||
connect(device, SIGNAL(modeChanged(bool)), this, SLOT(modeChanged(bool)));
|
||||
|
||||
connect(static_cast<MainWindow*>(parent), &MainWindow::switchToProfileCLI, this, &KbWidget::switchToProfile);
|
||||
connect(static_cast<MainWindow*>(parent), &MainWindow::switchToModeCLI, this, &KbWidget::switchToMode);
|
||||
|
||||
// Remove the Lighting and Performance tabs from non-RGB keyboards
|
||||
if(!device->features.contains("rgb")){
|
||||
ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->lightTab));
|
||||
@@ -447,8 +451,7 @@ void KbWidget::on_fwUpdButton_clicked(){
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
void KbWidget::on_layoutBox_activated(int index)
|
||||
{
|
||||
void KbWidget::on_layoutBox_activated(int index){
|
||||
// Can't use currentIndexChanged as it fires when the GUI is first drawn
|
||||
// before the layout has been initialised
|
||||
int idxLayout = ui->layoutBox->itemData(index).toInt();
|
||||
@@ -460,3 +463,37 @@ void KbWidget::on_layoutBox_activated(int index)
|
||||
CkbSettings::set(layoutSettingsPath.arg(device->usbSerial), KeyMap::getLayout(layout));
|
||||
device->layout(layout, true);
|
||||
}
|
||||
|
||||
void KbWidget::switchToProfile(QString profile){
|
||||
int len = device->profiles().length();
|
||||
for(int i = 0; i < len; i++){
|
||||
KbProfile* loopProfile = device->profiles().at(i);
|
||||
if(loopProfile->name() != profile)
|
||||
continue;
|
||||
|
||||
qDebug() << "Switching" << this->name() << "to" << profile;
|
||||
device->setCurrentProfile(loopProfile);
|
||||
|
||||
// Also update the dropdown
|
||||
ui->profileBox->setCurrentIndex(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void KbWidget::switchToMode(QString mode){
|
||||
KbProfile* currentProfile = device->currentProfile();
|
||||
int len = currentProfile->modes().length();
|
||||
|
||||
for(int i = 0; i < len; i++){
|
||||
KbMode* loopMode = currentProfile->modes().at(i);
|
||||
if(loopMode->name() != mode)
|
||||
continue;
|
||||
|
||||
qDebug() << "Switching" << this->name() << "to mode" << mode << "in" << currentProfile->name();
|
||||
device->setCurrentMode(loopMode);
|
||||
|
||||
// Also update the list
|
||||
ui->modesList->setCurrentRow(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +67,8 @@ private slots:
|
||||
void on_tabWidget_currentChanged(int index);
|
||||
void on_fwUpdButton_clicked();
|
||||
void on_layoutBox_activated(int index);
|
||||
void switchToProfile(QString profile);
|
||||
void switchToMode(QString mode);
|
||||
};
|
||||
|
||||
#endif // KBWIDGET_H
|
||||
|
||||
+40
-1
@@ -28,7 +28,9 @@ enum CommandLineParseResults {
|
||||
CommandLineVersionRequested,
|
||||
CommandLineHelpRequested,
|
||||
CommandLineClose,
|
||||
CommandLineBackground
|
||||
CommandLineBackground,
|
||||
CommandLineSwitchToProfile,
|
||||
CommandLineSwitchToMode,
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -57,6 +59,12 @@ CommandLineParseResults parseCommandLine(QCommandLineParser &parser, QString *er
|
||||
"Causes already running instance (if any) to exit.");
|
||||
parser.addOption(closeOption);
|
||||
|
||||
const QCommandLineOption switchToProfileOption(QStringList() << "p" << "profile", "Switches to the profile with the specified name on all devices.", "profile-name");
|
||||
parser.addOption(switchToProfileOption);
|
||||
|
||||
const QCommandLineOption switchToModeOption(QStringList() << "m" << "mode", "Switches to the mode either in the current profile, or in the one specified by --profile", "mode-name");
|
||||
parser.addOption(switchToModeOption);
|
||||
|
||||
/* parse arguments */
|
||||
if (!parser.parse(QCoreApplication::arguments())) {
|
||||
// set error, if there already are some
|
||||
@@ -85,6 +93,14 @@ CommandLineParseResults parseCommandLine(QCommandLineParser &parser, QString *er
|
||||
return CommandLineClose;
|
||||
}
|
||||
|
||||
if(parser.isSet(switchToProfileOption)) {
|
||||
return CommandLineSwitchToProfile;
|
||||
}
|
||||
|
||||
if(parser.isSet(switchToModeOption)) {
|
||||
return CommandLineSwitchToMode;
|
||||
}
|
||||
|
||||
/* no explicit argument was passed */
|
||||
return CommandLineOK;
|
||||
};
|
||||
@@ -208,6 +224,29 @@ int main(int argc, char *argv[]){
|
||||
else
|
||||
printf("ckb-next is not running.\n");
|
||||
return 0;
|
||||
case CommandLineSwitchToMode:
|
||||
case CommandLineSwitchToProfile:
|
||||
{
|
||||
QString profileName = parser.value("profile").left(30);
|
||||
QString modeName = parser.value("mode").left(30);
|
||||
|
||||
if(profileName.isEmpty() && modeName.isEmpty()) {
|
||||
printf("No valid profile or mode specified.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
QString switchStr;
|
||||
|
||||
if(!profileName.isEmpty())
|
||||
switchStr.append("SwitchToProfile: ").append(profileName).append("\nOption ");
|
||||
if(!modeName.isEmpty())
|
||||
switchStr.append("SwitchToMode: ").append(modeName);
|
||||
|
||||
if (!isRunning(switchStr.toUtf8().constData()))
|
||||
printf("ckb-next is not running.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
case CommandLineBackground:
|
||||
// If launched with --background, launch in background
|
||||
background = 1;
|
||||
|
||||
@@ -365,13 +365,17 @@ void MainWindow::timerTick(){
|
||||
showWindow();
|
||||
if(line.startsWith("Option ")){
|
||||
// New ckb option line
|
||||
QString option = line.split(" ")[1];
|
||||
QString option = line.section(' ', 1);
|
||||
if(option == "Open")
|
||||
// Bring to foreground
|
||||
showWindow();
|
||||
else if(option == "Close")
|
||||
// Quit application
|
||||
qApp->quit();
|
||||
else if(option.startsWith("SwitchToProfile"))
|
||||
emit switchToProfileCLI(option.section(' ', 1));
|
||||
else if(option.startsWith("SwitchToMode: "))
|
||||
emit switchToModeCLI(option.section(' ', 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,10 @@ public slots:
|
||||
void changeTrayIconToRGB();
|
||||
void handleTrayScrollEvt(bool up);
|
||||
|
||||
signals:
|
||||
void switchToProfileCLI(QString profile);
|
||||
void switchToModeCLI(QString mode);
|
||||
|
||||
private slots:
|
||||
void addDevice(Kb* device);
|
||||
void removeDevice(Kb* device);
|
||||
|
||||
Reference in New Issue
Block a user