Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Added no-tray option. Uses newer standard for config file placement. …
Browse files Browse the repository at this point in the history
…Added loading of controller profiles from the command-line. Resolves issue #5.
  • Loading branch information
Ryochan7 committed Jun 9, 2013
1 parent 865dd02 commit edba864
Show file tree
Hide file tree
Showing 16 changed files with 356 additions and 114 deletions.
114 changes: 105 additions & 9 deletions src/commandlineutility.cpp
Original file line number Diff line number Diff line change
@@ -1,40 +1,101 @@
#include <QDebug>
#include <QStringListIterator>
#include <QFileInfo>
#include <QTextStream>

#include "commandlineutility.h"
#include "common.h"

QRegExp CommandLineUtility::trayRegexp = QRegExp("--tray");
QRegExp CommandLineUtility::helpShortRegexp = QRegExp("-h");
QRegExp CommandLineUtility::helpLongRegexp = QRegExp("--help");
QRegExp CommandLineUtility::versionShortRegexp = QRegExp("-v");
QRegExp CommandLineUtility::versionLongRegexp = QRegExp("--version");
QRegExp CommandLineUtility::helpRegexp = QRegExp("(-h|--help)");
QRegExp CommandLineUtility::versionRegexp = QRegExp("(-v|--version)");
QRegExp CommandLineUtility::noTrayRegexp = QRegExp("--no-tray");
QRegExp CommandLineUtility::loadProfileRegexp = QRegExp("--profile");
QRegExp CommandLineUtility::loadProfileForControllerRegexp = QRegExp("--profile-controller");


CommandLineUtility::CommandLineUtility(QObject *parent) :
QObject(parent)
{
launchInTray = false;
helpRequest = false;
versionRequest = false;
hideTrayIcon = false;
profileLocation = QString();
controllerNumber = 0;
encounteredError = false;
}

void CommandLineUtility::parseArguments(QStringList& arguments)
{
QStringListIterator iter(arguments);
QTextStream out(stdout);
QTextStream errorsteam(stderr);

while (iter.hasNext())
{
QString temp = iter.next();
if (helpShortRegexp.exactMatch(temp) || helpLongRegexp.exactMatch(temp))
if (helpRegexp.exactMatch(temp))
{
helpRequest = true;
}
else if (versionShortRegexp.exactMatch(temp) || versionLongRegexp.exactMatch(temp))
else if (versionRegexp.exactMatch(temp))
{
versionRequest = true;
}
else if (trayRegexp.exactMatch(temp))
{
launchInTray = true;
hideTrayIcon = false;
}
else if (noTrayRegexp.exactMatch(temp))
{
hideTrayIcon = true;
launchInTray = false;
}
else if (loadProfileRegexp.exactMatch(temp))
{
if (iter.hasNext())
{
temp = iter.next();
QFileInfo fileInfo(temp);
if (fileInfo.exists())
{
if (fileInfo.suffix() != "xml")
{
errorsteam << tr("Profile location %1 is not an XML file.").arg(temp) << endl;
encounteredError = true;
}
else
{
profileLocation = fileInfo.absoluteFilePath();
}
}
else
{
errorsteam << tr("Profile location %1 does not exist.").arg(temp) << endl;
encounteredError = true;
}
}
}
else if (loadProfileForControllerRegexp.exactMatch(temp))
{
if (iter.hasNext())
{
temp = iter.next();

bool validNumber = false;
int tempNumber = temp.toInt(&validNumber);
if (validNumber)
{
controllerNumber = tempNumber;
}
else
{
errorsteam << tr("Controller number is not a valid number.") << endl;
encounteredError = true;
}
}
}
}
}
Expand All @@ -51,9 +112,14 @@ void CommandLineUtility::printHelp()
out << tr("Usage: antimicro [option]") << endl;
out << endl;
out << tr("Options") << ":" << endl;
out << "-h, --help " << " " << tr("Print help text") << endl;
out << "-v, --version" << " " << tr("Print version information") << endl;
out << "--tray " << " " << tr("Launch program in system tray only") << endl;
out << "-h, --help " << " " << tr("Print help text.") << endl;
out << "-v, --version " << " " << tr("Print version information.") << endl;
out << "--tray " << " " << tr("Launch program in system tray only.") << endl;
out << "--no-tray " << " " << tr("Launch program with the tray menu disabled.") << endl;
out << "--profile location " << " " <<
tr("Launch program with the configuration file\n selected as the default for all available\n controllers.")
<< endl;
out << "--profile-controller number" << " " << tr("Apply configuration file to a specific controller.") << endl;
}

bool CommandLineUtility::isHelpRequested()
Expand All @@ -71,3 +137,33 @@ void CommandLineUtility::printVersionString()
QTextStream out(stdout);
out << tr("AntiMicro version") << " " << PadderCommon::programVersion << endl;
}

bool CommandLineUtility::isTrayHidden()
{
return hideTrayIcon;
}

bool CommandLineUtility::hasProfile()
{
return !profileLocation.isEmpty();
}

bool CommandLineUtility::hasControllerNumber()
{
return (controllerNumber > 0);
}

QString CommandLineUtility::getProfileLocation()
{
return profileLocation;
}

unsigned int CommandLineUtility::getControllerNumber()
{
return controllerNumber;
}

bool CommandLineUtility::hasError()
{
return encounteredError;
}
21 changes: 16 additions & 5 deletions src/commandlineutility.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <QObject>
#include <QStringList>
#include <QRegExp>
#include <QTextStream>

class CommandLineUtility : public QObject
{
Expand All @@ -16,20 +15,32 @@ class CommandLineUtility : public QObject
bool isLaunchInTrayEnabled();
bool isHelpRequested();
bool isVersionRequested();
bool isTrayHidden();
bool hasProfile();
bool hasControllerNumber();
QString getProfileLocation();
unsigned int getControllerNumber();

void printHelp();
void printVersionString();

bool hasError();

protected:
bool launchInTray;
bool helpRequest;
bool versionRequest;
bool hideTrayIcon;
QString profileLocation;
unsigned int controllerNumber;
bool encounteredError;

static QRegExp trayRegexp;
static QRegExp helpShortRegexp;
static QRegExp helpLongRegexp;
static QRegExp versionShortRegexp;
static QRegExp versionLongRegexp;
static QRegExp helpRegexp;
static QRegExp versionRegexp;
static QRegExp noTrayRegexp;
static QRegExp loadProfileRegexp;
static QRegExp loadProfileForControllerRegexp;

signals:

Expand Down
6 changes: 5 additions & 1 deletion src/common.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
#ifndef COMMON_H
#define COMMON_H

#include <QtGlobal>
#include <QString>
#include <QDir>
#include <QSettings>

namespace PadderCommon
{
const QString configPath = QDir::homePath() + "/.antimicro";
const QString configPath = (!qgetenv("XDG_CONFIG_HOME").isEmpty()) ?
QString(qgetenv("XDG_CONFIG_HOME")) + "/antimicro" :
QDir::homePath() + "/.config/antimicro";
const QString configFileName = "antimicro_settings.ini";
const QString configFilePath = configPath + "/" + configFileName;
const QString pidFilePath = "/tmp/antimicro.pid";
const int LATESTCONFIGFILEVERSION = 3;
const QString programVersion = "0.7";
}
Expand Down
25 changes: 16 additions & 9 deletions src/inputdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,26 @@

#include "inputdaemon.h"

InputDaemon::InputDaemon(QHash<int, Joystick*> *joysticks, QObject *parent) :
InputDaemon::InputDaemon(QHash<int, Joystick*> *joysticks, bool graphical, QObject *parent) :
QObject(parent)
{
this->joysticks = joysticks;
this->stopped = false;
this->sdlIgnoreEvent = true;
this->graphical = graphical;

eventWorker = new SDLEventReader(joysticks);
thread = new QThread();
eventWorker->moveToThread(thread);

QTimer::singleShot(0, this, SLOT(refreshJoysticks()));
connect(thread, SIGNAL(started()), eventWorker, SLOT(performWork()));
connect(eventWorker, SIGNAL(eventRaised()), this, SLOT(run()));
thread->start();
//QTimer::singleShot(0, this, SLOT(refreshJoysticks()));
if (graphical)
{
connect(thread, SIGNAL(started()), eventWorker, SLOT(performWork()));
connect(eventWorker, SIGNAL(eventRaised()), this, SLOT(run()));
thread->start();
}
refreshJoysticks();
}

InputDaemon::~InputDaemon()
Expand Down Expand Up @@ -159,7 +164,6 @@ void InputDaemon::refreshJoysticks()
{
SDL_Joystick* joystick = SDL_JoystickOpen (i);
Joystick *curJoystick = new Joystick (joystick, this);
curJoystick->reset();

joysticks->insert(i, curJoystick);
}
Expand Down Expand Up @@ -200,9 +204,12 @@ void InputDaemon::quit()

// Wait for SDL to finish. Let worker destructor close SDL.
// Let InputDaemon destructor close thread instance.
QEventLoop q;
connect(eventWorker, SIGNAL(finished()), &q, SLOT(quit()));
q.exec();
if (graphical)
{
QEventLoop q;
connect(eventWorker, SIGNAL(finished()), &q, SLOT(quit()));
q.exec();
}

delete eventWorker;
eventWorker = 0;
Expand Down
5 changes: 3 additions & 2 deletions src/inputdaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ class InputDaemon : public QObject
{
Q_OBJECT
public:
InputDaemon (QHash<int, Joystick*> *joysticks, QObject *parent=0);
InputDaemon (QHash<int, Joystick*> *joysticks, bool graphical=true, QObject *parent=0);
~InputDaemon();

protected:
QHash<int, Joystick*> *joysticks;
bool stopped;
bool sdlIgnoreEvent;
bool graphical;

SDLEventReader *eventWorker;
QThread *thread;
Expand All @@ -33,10 +34,10 @@ public slots:
void quit();
void refresh();
void refreshJoystick(Joystick *joystick);
void refreshJoysticks();

private slots:
void stop();
void refreshJoysticks ();
};

#endif // INPUTDAEMONTHREAD_H
5 changes: 0 additions & 5 deletions src/joybutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,11 +608,6 @@ void JoyButton::mouseEvent()
}
}

void JoyButton::mouseSingleEvent()
{

}

void JoyButton::setUseTurbo(bool useTurbo)
{
bool initialState = this->useTurbo;
Expand Down
1 change: 0 additions & 1 deletion src/joybutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ public slots:
private slots:
void turboEvent();
virtual void mouseEvent();
void mouseSingleEvent();
void createDeskEvent();
void releaseDeskEvent(bool skipsetchange=false);
void releaseActiveSlots();
Expand Down
31 changes: 1 addition & 30 deletions src/joybuttonwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,14 @@
JoyButtonWidget::JoyButtonWidget(QWidget *parent) :
QPushButton(parent)
{

normal = this->palette();
flashing = this->palette();

QColor highlightColor = QColor(0, 0, 255);
flashing.setCurrentColorGroup(QPalette::Inactive);
flashing.setColor(QPalette::Button, highlightColor);
flashing.setColor(QPalette::Light, highlightColor.light(150));
flashing.setColor(QPalette::Midlight, highlightColor.light(125));
flashing.setColor(QPalette::Dark, highlightColor.dark(200));
flashing.setColor(QPalette::Mid, highlightColor.dark(150));

setPalette(flashing);
isflashing = false;
}

JoyButtonWidget::JoyButtonWidget(JoyButton *button, QWidget *parent) :
QPushButton(parent)
{

this->button = button;

normal = this->palette();
flashing = this->palette();
QColor highlightColor = QColor(0, 0, 255);

flashing.setCurrentColorGroup(QPalette::Inactive);
flashing.setColor(QPalette::Button, highlightColor);
flashing.setColor(QPalette::Light, highlightColor.light(150));
flashing.setColor(QPalette::Midlight, highlightColor.light(125));
flashing.setColor(QPalette::Dark, highlightColor.dark(200));
flashing.setColor(QPalette::Mid, highlightColor.dark(150));

setPalette(normal);
isflashing = false;

setText(button->getName());
Expand All @@ -59,8 +33,7 @@ JoyButton* JoyButtonWidget::getJoyButton()
void JoyButtonWidget::flash()
{
isflashing = true;
//setPalette(flashing);
//update();

this->style()->unpolish(this);
this->style()->polish(this);

Expand All @@ -70,8 +43,6 @@ void JoyButtonWidget::flash()
void JoyButtonWidget::unflash()
{
isflashing = false;
//setPalette(normal);
//update();

this->style()->unpolish(this);
this->style()->polish(this);
Expand Down
2 changes: 0 additions & 2 deletions src/joybuttonwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class JoyButtonWidget : public QPushButton

protected:
JoyButton* button;
QPalette normal;
QPalette flashing;
bool isflashing;

signals:
Expand Down
Loading

0 comments on commit edba864

Please sign in to comment.