internationalization (but no localization yet)

This commit is contained in:
Mathias Panzenböck
2014-02-23 18:27:27 +01:00
parent cad0fc343d
commit 45efb2e941
14 changed files with 111 additions and 97 deletions

View File

@ -282,20 +282,20 @@ QString Axis::status() {
if (mode == Keyboard) { if (mode == Keyboard) {
if (throttle == 0) { if (throttle == 0) {
if (puseMouse != nuseMouse) { if (puseMouse != nuseMouse) {
result += "KEYBOARD/MOUSE"; result += tr("KEYBOARD/MOUSE");
} }
else if (puseMouse) { else if (puseMouse) {
result += "MOUSE"; result += tr("MOUSE");
} }
else { else {
result += "KEYBOARD"; result += tr("KEYBOARD");
} }
} }
else { else {
result += "THROTTLE"; result += tr("THROTTLE");
} }
} }
else result += "MOUSE"; else result += tr("MOUSE");
return result + "]"; return result + "]";
} }

View File

@ -23,26 +23,26 @@ AxisEdit::AxisEdit( Axis* ax )
QVBoxLayout* v2 = new QVBoxLayout(); QVBoxLayout* v2 = new QVBoxLayout();
v2->setMargin(5); v2->setMargin(5);
v2->setSpacing(5); v2->setSpacing(5);
chkGradient = new QCheckBox("&Gradient", this); chkGradient = new QCheckBox(tr("&Gradient"), this);
chkGradient->setChecked(axis->gradient); chkGradient->setChecked(axis->gradient);
connect(chkGradient, SIGNAL(toggled(bool)), this, SLOT( gradientChanged( bool ))); connect(chkGradient, SIGNAL(toggled(bool)), this, SLOT( gradientChanged( bool )));
v2->addWidget(chkGradient); v2->addWidget(chkGradient);
cmbMode = new QComboBox(this); cmbMode = new QComboBox(this);
cmbMode->insertItem((int) Axis::Keyboard, QString("Keyboard/Mouse Button"), Qt::DisplayRole); cmbMode->insertItem((int) Axis::Keyboard, tr("Keyboard/Mouse Button"), Qt::DisplayRole);
cmbMode->insertItem((int) Axis::MousePosVert,QString("Mouse (Vert.)"),Qt::DisplayRole); cmbMode->insertItem((int) Axis::MousePosVert, tr("Mouse (Vert.)"),Qt::DisplayRole);
cmbMode->insertItem((int) Axis::MouseNegVert, QString("Mouse (Vert. Rev.)"), Qt::DisplayRole); cmbMode->insertItem((int) Axis::MouseNegVert, tr("Mouse (Vert. Rev.)"), Qt::DisplayRole);
cmbMode->insertItem((int) Axis::MousePosHor, "Mouse (Hor.)", Qt::DisplayRole); cmbMode->insertItem((int) Axis::MousePosHor, tr("Mouse (Hor.)"), Qt::DisplayRole);
cmbMode->insertItem((int) Axis::MouseNegHor, QString("Mouse (Hor. Rev.)"), Qt::DisplayRole); cmbMode->insertItem((int) Axis::MouseNegHor, tr("Mouse (Hor. Rev.)"), Qt::DisplayRole);
cmbMode->setCurrentIndex( axis->mode ); cmbMode->setCurrentIndex( axis->mode );
connect(cmbMode, SIGNAL(activated(int)), this, SLOT( modeChanged( int ))); connect(cmbMode, SIGNAL(activated(int)), this, SLOT( modeChanged( int )));
v2->addWidget(cmbMode); v2->addWidget(cmbMode);
cmbTransferCurve = new QComboBox(this); cmbTransferCurve = new QComboBox(this);
cmbTransferCurve->insertItem(Axis::Linear, QString("Linear"), Qt::DisplayRole); cmbTransferCurve->insertItem(Axis::Linear, tr("Linear"), Qt::DisplayRole);
cmbTransferCurve->insertItem(Axis::Quadratic, QString("Quadratic"),Qt::DisplayRole ); cmbTransferCurve->insertItem(Axis::Quadratic, tr("Quadratic"), Qt::DisplayRole );
cmbTransferCurve->insertItem(Axis::Cubic, QString("Cubic"),Qt::DisplayRole ); cmbTransferCurve->insertItem(Axis::Cubic, tr("Cubic"), Qt::DisplayRole );
cmbTransferCurve->insertItem(Axis::QuadraticExtreme, QString("Quadratic Extreme"), Qt::DisplayRole); cmbTransferCurve->insertItem(Axis::QuadraticExtreme, tr("Quadratic Extreme"), Qt::DisplayRole);
cmbTransferCurve->insertItem(Axis::PowerFunction, QString("Power Function"), Qt::DisplayRole); cmbTransferCurve->insertItem(Axis::PowerFunction, tr("Power Function"), Qt::DisplayRole);
cmbTransferCurve->setCurrentIndex( axis->transferCurve ); cmbTransferCurve->setCurrentIndex( axis->transferCurve );
cmbTransferCurve->setEnabled(axis->gradient); cmbTransferCurve->setEnabled(axis->gradient);
connect(cmbTransferCurve, SIGNAL(activated(int)), this, SLOT( transferCurveChanged( int ))); connect(cmbTransferCurve, SIGNAL(activated(int)), this, SLOT( transferCurveChanged( int )));
@ -55,14 +55,14 @@ AxisEdit::AxisEdit( Axis* ax )
v2->setSpacing(5); v2->setSpacing(5);
v2->setMargin(5); v2->setMargin(5);
//v2->setAutoAdd(true); //v2->setAutoAdd(true);
QLabel *mouseLabel = new QLabel("&Mouse Speed", mouseBox); QLabel *mouseLabel = new QLabel(tr("&Mouse Speed"), mouseBox);
v2->addWidget(mouseLabel); v2->addWidget(mouseLabel);
spinSpeed = new QSpinBox(mouseBox); spinSpeed = new QSpinBox(mouseBox);
spinSpeed->setRange(0,MAXMOUSESPEED); spinSpeed->setRange(0,MAXMOUSESPEED);
spinSpeed->setSingleStep(1); spinSpeed->setSingleStep(1);
spinSpeed->setValue(axis->maxSpeed); spinSpeed->setValue(axis->maxSpeed);
v2->addWidget(spinSpeed); v2->addWidget(spinSpeed);
lblSensitivity = new QLabel("&Sensitivity", mouseBox); lblSensitivity = new QLabel(tr("&Sensitivity"), mouseBox);
v2->addWidget(lblSensitivity); v2->addWidget(lblSensitivity);
spinSensitivity = new QDoubleSpinBox(mouseBox); spinSensitivity = new QDoubleSpinBox(mouseBox);
spinSensitivity->setRange(1e-3F, 1e+3F); spinSensitivity->setRange(1e-3F, 1e+3F);
@ -86,9 +86,9 @@ AxisEdit::AxisEdit( Axis* ax )
btnNeg = new KeyButton(axis->getName(),axis->nkeycode,keyBox,true,axis->nuseMouse); btnNeg = new KeyButton(axis->getName(),axis->nkeycode,keyBox,true,axis->nuseMouse);
cmbThrottle = new QComboBox(keyBox); cmbThrottle = new QComboBox(keyBox);
cmbThrottle->insertItem(0,"Neg. Throttle",Qt::DisplayRole); cmbThrottle->insertItem(0, tr("Neg. Throttle"), Qt::DisplayRole);
cmbThrottle->insertItem(1,"No Throttle",Qt::DisplayRole); cmbThrottle->insertItem(1, tr("No Throttle"), Qt::DisplayRole);
cmbThrottle->insertItem(2,"Pos. Throttle",Qt::DisplayRole); cmbThrottle->insertItem(2, tr("Pos. Throttle"), Qt::DisplayRole);
cmbThrottle->setCurrentIndex(axis->throttle + 1); cmbThrottle->setCurrentIndex(axis->throttle + 1);
connect( cmbThrottle, SIGNAL( activated( int )), this, SLOT( throttleChanged( int ))); connect( cmbThrottle, SIGNAL( activated( int )), this, SLOT( throttleChanged( int )));

View File

@ -125,10 +125,10 @@ bool Button::isDefault() {
QString Button::status() { QString Button::status() {
if (useMouse) { if (useMouse) {
return QString("%1 : Mouse %2").arg(getName()).arg(keycode); return tr("%1 : Mouse %2").arg(getName()).arg(keycode);
} }
else { else {
return QString("%1 : %2").arg(getName(), ktos(keycode)); return tr("%1 : %2").arg(getName(), ktos(keycode));
} }
} }

View File

@ -9,7 +9,7 @@ ButtonEdit::ButtonEdit(Button* butt)
setModal(true); setModal(true);
//build the dialog! //build the dialog!
button = butt; button = butt;
setWindowTitle("Set " + button->getName()); setWindowTitle(tr("Set %1").arg(button->getName()));
setWindowIcon(QPixmap(QJOYPAD_ICON24)); setWindowIcon(QPixmap(QJOYPAD_ICON24));
QVBoxLayout* v = new QVBoxLayout(this); QVBoxLayout* v = new QVBoxLayout(this);
@ -20,10 +20,10 @@ ButtonEdit::ButtonEdit(Button* butt)
v->addWidget(btnKey); v->addWidget(btnKey);
QHBoxLayout* h = new QHBoxLayout(); QHBoxLayout* h = new QHBoxLayout();
chkSticky = new QCheckBox("&Sticky", this); chkSticky = new QCheckBox(tr("&Sticky"), this);
chkSticky->setChecked(button->sticky); chkSticky->setChecked(button->sticky);
h->addWidget(chkSticky); h->addWidget(chkSticky);
chkRapid = new QCheckBox("&Rapid Fire", this); chkRapid = new QCheckBox(tr("&Rapid Fire"), this);
chkRapid->setChecked(button->rapidfire); chkRapid->setChecked(button->rapidfire);
h->addWidget(chkRapid); h->addWidget(chkRapid);
v->addLayout(h); v->addLayout(h);

View File

@ -7,21 +7,19 @@ GetKey::GetKey( QString button, bool m )
{ {
//prepare the dialog //prepare the dialog
mouse = m; mouse = m;
setWindowTitle( "Choose a key" ); setWindowTitle( tr("Choose a key") );
setWindowIcon(QIcon(QJOYPAD_ICON24)); setWindowIcon(QIcon(QJOYPAD_ICON24));
//I'd use a QLabel, but that steals x11Events! //I'd use a QLabel, but that steals x11Events!
//So, I'll draw the text directly. That means //So, I'll draw the text directly. That means
//I need to resolve the size of the dialog by hand: //I need to resolve the size of the dialog by hand:
text = "Choose a new key "; text = (mouse ? tr("Choose a new key or mouse button for %1") : tr("Choose a new key for %1")).arg(button);
if (mouse) text += "or mouse button ";
text += "for " + button;
QRect rect = fontMetrics().boundingRect( text ); QRect rect = fontMetrics().boundingRect( text );
//I calculate the size based on the first line of text, which is longer. //I calculate the size based on the first line of text, which is longer.
//The fontMetrics function is dumb and would treat the string with a //The fontMetrics function is dumb and would treat the string with a
//newline in it as a continues flow of characters if I did the whole string //newline in it as a continues flow of characters if I did the whole string
//at once. //at once.
text += "\n(Ctrl-X for no key)"; text += tr("\n(Ctrl-X for no key)");
//now I add 20 pixels of padding and double the height to make room for //now I add 20 pixels of padding and double the height to make room for
//two lines. //two lines.
setFixedSize( QSize( rect.width() + 20, rect.height()*2 + 20 ) ); setFixedSize( QSize( rect.width() + 20, rect.height()*2 + 20 ) );

View File

@ -9,7 +9,7 @@ FloatingIcon::FloatingIcon( const QString &icon, QMenu *popup, QWidget *parent,
setAttribute(Qt::WA_QuitOnClose); setAttribute(Qt::WA_QuitOnClose);
setAttribute(Qt::WA_TranslucentBackground); setAttribute(Qt::WA_TranslucentBackground);
setWindowFlags(Qt::FramelessWindowHint); setWindowFlags(Qt::FramelessWindowHint);
setWindowTitle(QJOYPAD_NAME " Floating Icon"); setWindowTitle(tr("%1 Floating Icon").arg(QJOYPAD_NAME));
pop = popup; pop = popup;
setFixedSize(this->icon.width(),this->icon.height()); setFixedSize(this->icon.width(),this->icon.height());

View File

@ -137,14 +137,14 @@ bool JoyPad::readConfig( QTextStream &stream ) {
if (num > 0) { if (num > 0) {
stream >> ch; stream >> ch;
if (ch != ':') { if (ch != ':') {
errorBox("Layout file error", QString("Expected ':', found '%1'.").arg(ch)); errorBox(tr("Layout file error"), tr("Expected ':', found '%1'.").arg(ch));
return false; return false;
} }
if (buttons[num-1] == 0) { if (buttons[num-1] == 0) {
buttons.insert(num-1,new Button(num-1,this)); buttons.insert(num-1,new Button(num-1,this));
} }
if (!buttons[num-1]->read( stream )) { if (!buttons[num-1]->read( stream )) {
errorBox("Layout file error", QString("Error reading Button %1").arg(num)); errorBox(tr("Layout file error"), tr("Error reading Button %1").arg(num));
return false; return false;
} }
} }
@ -157,20 +157,20 @@ bool JoyPad::readConfig( QTextStream &stream ) {
if (num > 0) { if (num > 0) {
stream >> ch; stream >> ch;
if (ch != ':') { if (ch != ':') {
errorBox("Layout file error", QString("Expected ':', found '%1'.").arg(ch)); errorBox(tr("Layout file error"), tr("Expected ':', found '%1'.").arg(ch));
return false; return false;
} }
if (axes[num-1] == 0) { if (axes[num-1] == 0) {
axes.insert(num-1,new Axis(num-1,this)); axes.insert(num-1,new Axis(num-1,this));
} }
if (!axes[num-1]->read(stream)) { if (!axes[num-1]->read(stream)) {
errorBox("Layout file error", QString("Error reading Axis %1").arg(num)); errorBox(tr("Layout file error"), tr("Error reading Axis %1").arg(num));
return false; return false;
} }
} }
} }
else { else {
errorBox( "Layout file error", QString("Error while reading layout. Unrecognized word: %1").arg(word) ); errorBox(tr("Layout file error"), tr("Error while reading layout. Unrecognized word: %1").arg(word));
return false; return false;
} }
stream >> word; stream >> word;
@ -248,7 +248,7 @@ void JoyPad::handleJoyEvents() {
void JoyPad::releaseWidget() { void JoyPad::releaseWidget() {
//this is how we know that there is no longer a JoyPadWidget around. //this is how we know that there is no longer a JoyPadWidget around.
jpw = NULL; jpw = 0;
} }
void JoyPad::errorRead() { void JoyPad::errorRead() {

View File

@ -42,7 +42,7 @@ class JoyPad : public QObject {
//read the dimensions on the real joystick and use them //read the dimensions on the real joystick and use them
void open( int dev ); void open( int dev );
const QString& getDeviceId() const { return deviceId; } const QString& getDeviceId() const { return deviceId; }
QString getName() const { return QString("Joystick %1 (%2)").arg(index+1).arg(deviceId); } QString getName() const { return tr("Joystick %1 (%2)").arg(index+1).arg(deviceId); }
int getIndex() const { return index; } int getIndex() const { return index; }
private: private:

View File

@ -35,11 +35,11 @@ JoyPadWidget::JoyPadWidget( JoyPad* jp, int i, QWidget* parent )
insertCounter ++; insertCounter ++;
} }
insertCounter += 2; insertCounter += 2;
btnClear = new QPushButton(QIcon::fromTheme("edit-clear"), "Clear", this); btnClear = new QPushButton(QIcon::fromTheme("edit-clear"), tr("Clear"), this);
connect(btnClear, SIGNAL(clicked()), this, SLOT(clear())); connect(btnClear, SIGNAL(clicked()), this, SLOT(clear()));
layoutMain->addWidget(btnClear, insertCounter / 2, insertCounter % 2); layoutMain->addWidget(btnClear, insertCounter / 2, insertCounter % 2);
insertCounter++; insertCounter++;
btnAll = new QPushButton("Quick Set", this); btnAll = new QPushButton(tr("Quick Set"), this);
layoutMain->addWidget(btnAll, insertCounter / 2, insertCounter % 2); layoutMain->addWidget(btnAll, insertCounter / 2, insertCounter % 2);
connect(btnAll, SIGNAL(clicked()), this, SLOT(setAll())); connect(btnAll, SIGNAL(clicked()), this, SLOT(setAll()));
} }
@ -57,8 +57,9 @@ void JoyPadWidget::flash( bool on ) {
flashcount += (on?1:-1); flashcount += (on?1:-1);
//if we were on and should now be off, or visa versa, flash the whole widget //if we were on and should now be off, or visa versa, flash the whole widget
if (wasOn != (flashcount != 0)) if (wasOn != (flashcount != 0)) {
emit flashed(index); emit flashed(index);
}
} }
void JoyPadWidget::update() { void JoyPadWidget::update() {

View File

@ -80,7 +80,7 @@ const QString ktos( int keycode )
KeyButton::KeyButton( QString name, int val, QWidget* parent, bool m, bool nowMouse) KeyButton::KeyButton( QString name, int val, QWidget* parent, bool m, bool nowMouse)
:QPushButton(nowMouse?"Mouse " + QString::number(val):QString(ktos(val)), parent) { :QPushButton(nowMouse?tr("Mouse %1").arg(val):ktos(val), parent) {
mouse = m; mouse = m;
mouseClicked = nowMouse; mouseClicked = nowMouse;
buttonname = name; buttonname = name;
@ -102,11 +102,11 @@ void KeyButton::onClick() {
if (value > MOUSE_OFFSET) { if (value > MOUSE_OFFSET) {
mouseClicked = true; mouseClicked = true;
value -= MOUSE_OFFSET; value -= MOUSE_OFFSET;
setText( "Mouse " + QString::number(value)); setText(tr("Mouse %1").arg(value));
} }
//otherwise, it was a key press! //otherwise, it was a key press!
else { else {
mouseClicked = false; mouseClicked = false;
setText( ktos(value)); setText(ktos(value));
} }
} }

View File

@ -11,9 +11,9 @@ LayoutManager::LayoutManager( bool useTrayIcon, const QString &devdir, const QSt
: devdir(devdir), settingsDir(settingsDir), : devdir(devdir), settingsDir(settingsDir),
layoutGroup(new QActionGroup(this)), layoutGroup(new QActionGroup(this)),
titleAction(new QAction(this)), titleAction(new QAction(this)),
updateDevicesAction(new QAction(QIcon::fromTheme("view-refresh"),"Update &Joystick Devices",this)), updateDevicesAction(new QAction(QIcon::fromTheme("view-refresh"),tr("Update &Joystick Devices"),this)),
updateLayoutsAction(new QAction(QIcon::fromTheme("view-refresh"),"Update &Layout List",this)), updateLayoutsAction(new QAction(QIcon::fromTheme("view-refresh"),tr("Update &Layout List"),this)),
quitAction(new QAction(QIcon::fromTheme("application-exit"),"&Quit",this)), quitAction(new QAction(QIcon::fromTheme("application-exit"),tr("&Quit"),this)),
le(0) { le(0) {
#ifdef WITH_LIBUDEV #ifdef WITH_LIBUDEV
@ -22,8 +22,8 @@ LayoutManager::LayoutManager( bool useTrayIcon, const QString &devdir, const QSt
monitor = 0; monitor = 0;
if (!initUDev()) { if (!initUDev()) {
errorBox("UDev Error", "Error creating UDev monitor. " errorBox(tr("UDev Error"), tr("Error creating UDev monitor. "
"QJoyPad will still work, but it won't automatically update the joypad device list."); "QJoyPad will still work, but it won't automatically update the joypad device list."));
} }
#endif #endif
@ -205,7 +205,7 @@ bool LayoutManager::load(const QString& name) {
num = word.toInt(&okay); num = word.toInt(&okay);
//make sure the number of the joystick is valid //make sure the number of the joystick is valid
if (!okay || num < 1) { if (!okay || num < 1) {
errorBox( "Load error", QString("Error reading joystick definition. Unexpected token \"%1\". Expected a positive number.").arg(word)); errorBox( tr("Load error"), tr("Error reading joystick definition. Unexpected token \"%1\". Expected a positive number.").arg(word));
if (name != currentLayout) reload(); if (name != currentLayout) reload();
else clear(); else clear();
return false; return false;
@ -213,7 +213,7 @@ bool LayoutManager::load(const QString& name) {
stream.skipWhiteSpace(); stream.skipWhiteSpace();
stream >> ch; stream >> ch;
if (ch != QChar('{')) { if (ch != QChar('{')) {
errorBox( "Load error", QString("Error reading joystick definition. Unexpected character \"%1\". Expected '{'.").arg(ch)); errorBox( tr("Load error"), tr("Error reading joystick definition. Unexpected character \"%1\". Expected '{'.").arg(ch));
if (name != currentLayout) reload(); if (name != currentLayout) reload();
else clear(); else clear();
return false; return false;
@ -225,7 +225,7 @@ bool LayoutManager::load(const QString& name) {
} }
//try to read the joypad, report error on fail. //try to read the joypad, report error on fail.
if (!joypads[index]->readConfig(stream)) { if (!joypads[index]->readConfig(stream)) {
errorBox( "Load error", QString("Error reading definition for joystick %1.").arg(index)); errorBox( tr("Load error"), tr("Error reading definition for joystick %1.").arg(index));
//if this was attempting to change to a new layout and it failed, //if this was attempting to change to a new layout and it failed,
//revert back to the old layout. //revert back to the old layout.
if (name != currentLayout) reload(); if (name != currentLayout) reload();
@ -240,7 +240,7 @@ bool LayoutManager::load(const QString& name) {
stream.readLine(); stream.readLine();
} }
else { else {
errorBox("Load error", QString("Error reading joystick definition. Unexpected token \"%1\". Expected \"Joystick\".").arg(word)); errorBox(tr("Load error"), tr("Error reading joystick definition. Unexpected token \"%1\". Expected \"Joystick\".").arg(word));
if (name != currentLayout) reload(); if (name != currentLayout) reload();
else clear(); else clear();
return false; return false;
@ -304,22 +304,26 @@ void LayoutManager::save() {
file.close(); file.close();
} }
//if it's not, error. //if it's not, error.
else else {
errorBox("Save error", "Could not open file " + filename + ", layout not saved."); errorBox(tr("Save error"), tr("Could not open file %1, layout not saved.").arg(filename));
}
} }
void LayoutManager::saveAs() { void LayoutManager::saveAs() {
bool ok; bool ok;
//request a new name! //request a new name!
QString name = QInputDialog::getText(0, QJOYPAD_NAME" - Name new layout","Enter a name for the new layout:", QLineEdit::Normal, QString::null, &ok ); QString name = QInputDialog::getText(le,
tr("%1 - Name new layout").arg(QJOYPAD_NAME),
tr("Enter a name for the new layout:"),
QLineEdit::Normal, QString::null, &ok );
if (!ok) { if (!ok) {
return; return;
} }
QFile file(settingsDir + name + ".lyt"); QFile file(settingsDir + name + ".lyt");
//don't overwrite an existing layout. //don't overwrite an existing layout.
if (file.exists()) { if (file.exists()) {
errorBox("Save error", "That name's already taken!"); errorBox(tr("Save error"), tr("That name's already taken!"));
return; return;
} }
@ -346,12 +350,12 @@ void LayoutManager::saveDefault() {
void LayoutManager::remove() { void LayoutManager::remove() {
if (currentLayout.isNull()) return; if (currentLayout.isNull()) return;
if (QMessageBox::warning(0, QJOYPAD_NAME" - Delete layout?", if (QMessageBox::warning(le, tr("%1 - Delete layout?").arg(QJOYPAD_NAME),
QString("Remove layout %1 permanently from your hard drive?").arg(currentLayout), "Delete", "Cancel", 0, 0, 1 ) == 1) tr("Remove layout %1 permanently from your hard drive?").arg(currentLayout), tr("Delete"), tr("Cancel"), 0, 0, 1 ) == 1)
return; return;
QString filename = getFileName( currentLayout ); QString filename = getFileName( currentLayout );
if (!QFile(filename).remove()) { if (!QFile(filename).remove()) {
errorBox("Remove error", "Could not remove file " + filename); errorBox(tr("Remove error"), tr("Could not remove file %1").arg(filename));
} }
fillPopup(); fillPopup();
@ -392,7 +396,8 @@ void LayoutManager::setLayoutName(const QString& name) {
void LayoutManager::iconClick() { void LayoutManager::iconClick() {
//don't show the dialog if there aren't any joystick devices plugged in //don't show the dialog if there aren't any joystick devices plugged in
if (available.isEmpty()) { if (available.isEmpty()) {
errorBox("No joystick devices available","No joystick devices are currently available to configure.\nPlease plug in a gaming device and select\n\"Update Joystick Devices\" from the popup menu."); errorBox(tr("No joystick devices available"),
tr("No joystick devices are currently available to configure.\nPlease plug in a gaming device and select\n\"Update Joystick Devices\" from the popup menu."));
return; return;
} }
if (le) { if (le) {
@ -428,14 +433,16 @@ void LayoutManager::fillPopup() {
trayMenu.clear(); trayMenu.clear();
//make a list of joystick devices //make a list of joystick devices
QString title = "Joysticks: "; QString title;
if (available.isEmpty()) { if (available.isEmpty()) {
title += "(none)"; title = tr("Joysticks: (none)");
} }
else { else {
QStringList pads;
foreach (JoyPad *joypad, available) { foreach (JoyPad *joypad, available) {
title += QString("%1 ").arg(joypad->getIndex() + 1); pads.append(QString::number(joypad->getIndex() + 1));
} }
title = tr("Joysticks: %1").arg(pads.join(" "));
} }
trayMenu.setTitle(title); trayMenu.setTitle(title);
@ -449,7 +456,7 @@ void LayoutManager::fillPopup() {
trayMenu.addSeparator(); trayMenu.addSeparator();
//add null layout //add null layout
QAction *action = trayMenu.addAction("[NO LAYOUT]"); QAction *action = trayMenu.addAction(tr("[NO LAYOUT]"));
action->setCheckable(true); action->setCheckable(true);
action->setActionGroup(layoutGroup); action->setActionGroup(layoutGroup);
//put a check by the current one ;) //put a check by the current one ;)

View File

@ -22,16 +22,16 @@ LayoutEdit::LayoutEdit( LayoutManager* l ): QWidget(NULL) {
g->addWidget(cmbLayouts,0,0,1,4); g->addWidget(cmbLayouts,0,0,1,4);
//most of these buttons can link directly into slots in the LayoutManager //most of these buttons can link directly into slots in the LayoutManager
btnAdd = new QPushButton(QIcon::fromTheme("list-add"), "&Add", frame); btnAdd = new QPushButton(QIcon::fromTheme("list-add"), tr("&Add"), frame);
connect(btnAdd, SIGNAL(clicked()), lm, SLOT(saveAs())); connect(btnAdd, SIGNAL(clicked()), lm, SLOT(saveAs()));
g->addWidget(btnAdd,1,0); g->addWidget(btnAdd,1,0);
btnRem = new QPushButton(QIcon::fromTheme("list-remove"), "&Remove", frame); btnRem = new QPushButton(QIcon::fromTheme("list-remove"), tr("&Remove"), frame);
connect(btnRem, SIGNAL(clicked()), lm, SLOT(remove())); connect(btnRem, SIGNAL(clicked()), lm, SLOT(remove()));
g->addWidget(btnRem,1,1); g->addWidget(btnRem,1,1);
btnUpd = new QPushButton(QIcon::fromTheme("document-save"), "&Save", frame); btnUpd = new QPushButton(QIcon::fromTheme("document-save"), tr("&Save"), frame);
connect(btnUpd, SIGNAL(clicked()), lm, SLOT(save())); connect(btnUpd, SIGNAL(clicked()), lm, SLOT(save()));
g->addWidget(btnUpd,1,2); g->addWidget(btnUpd,1,2);
btnRev = new QPushButton(QIcon::fromTheme("document-revert"), "Re&vert", frame); btnRev = new QPushButton(QIcon::fromTheme("document-revert"), tr("Re&vert"), frame);
connect(btnRev, SIGNAL(clicked()), lm, SLOT(reload())); connect(btnRev, SIGNAL(clicked()), lm, SLOT(reload()));
g->addWidget(btnRev,1,3); g->addWidget(btnRev,1,3);
mainLayout->addWidget( frame ); mainLayout->addWidget( frame );
@ -73,10 +73,10 @@ LayoutEdit::LayoutEdit( LayoutManager* l ): QWidget(NULL) {
QHBoxLayout* h = new QHBoxLayout(0); QHBoxLayout* h = new QHBoxLayout(0);
h->setMargin(0); h->setMargin(0);
h->setSpacing(5); h->setSpacing(5);
QPushButton* close = new QPushButton(QIcon::fromTheme("window-close"), "&Close Dialog", this ); QPushButton* close = new QPushButton(QIcon::fromTheme("window-close"), tr("&Close Dialog"), this );
connect(close, SIGNAL(clicked()), this, SLOT(close())); connect(close, SIGNAL(clicked()), this, SLOT(close()));
h->addWidget(close); h->addWidget(close);
QPushButton* quit = new QPushButton(QIcon::fromTheme("application-exit"), "&Quit", this ); QPushButton* quit = new QPushButton(QIcon::fromTheme("application-exit"), tr("&Quit"), this );
connect( quit, SIGNAL( clicked() ), qApp, SLOT(quit())); connect( quit, SIGNAL( clicked() ), qApp, SLOT(quit()));
h->addWidget(quit); h->addWidget(quit);
mainLayout->addLayout(h); mainLayout->addLayout(h);
@ -103,7 +103,7 @@ void LayoutEdit::setLayout(const QString &layout) {
void LayoutEdit::updateLayoutList() { void LayoutEdit::updateLayoutList() {
//blank the list, then load in new names from the LayoutManager. //blank the list, then load in new names from the LayoutManager.
cmbLayouts->clear(); cmbLayouts->clear();
cmbLayouts->addItem("[NO LAYOUT]", QVariant(QString::null)); cmbLayouts->addItem(tr("[NO LAYOUT]"), QVariant(QString::null));
if (lm->currentLayout.isNull()) { if (lm->currentLayout.isNull()) {
cmbLayouts->setCurrentIndex(0); cmbLayouts->setCurrentIndex(0);
} }

View File

@ -9,6 +9,7 @@
#include <QFile> #include <QFile>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include <QPointer> #include <QPointer>
#include <QFileInfo>
//to load layouts //to load layouts
#include "layout.h" #include "layout.h"
@ -24,8 +25,7 @@ QPointer<LayoutManager> layoutManagerPtr;
//signal handler for SIGUSR2 //signal handler for SIGUSR2
//SIGUSR2 means that a new layout should be loaded. It is saved in //SIGUSR2 means that a new layout should be loaded. It is saved in
// ~/.qjoypad/layout, where the last used layout is put. // ~/.qjoypad/layout, where the last used layout is put.
void catchSIGUSR2( int sig ) void catchSIGUSR2( int sig ) {
{
if (layoutManagerPtr) layoutManagerPtr->load(); if (layoutManagerPtr) layoutManagerPtr->load();
//remember to catch this signal again next time. //remember to catch this signal again next time.
signal( sig, catchSIGUSR2 ); signal( sig, catchSIGUSR2 );
@ -62,7 +62,8 @@ int main( int argc, char **argv )
//if there is no new directory and we can't make it, complain //if there is no new directory and we can't make it, complain
if (!dir.exists() && !dir.mkdir(settingsDir)) { if (!dir.exists() && !dir.mkdir(settingsDir)) {
printf("Couldn't create the QJoyPad save directory (%s)!", settingsDir.toStdString().c_str()); errorBox(app.tr("Couldn't create the QJoyPad save directory"),
app.tr("Couldn't create the QJoyPad save directory: %s").arg(settingsDir));
return 1; return 1;
} }
@ -93,8 +94,8 @@ int main( int argc, char **argv )
switch (c) { switch (c) {
case 'h': case 'h':
printf("%s\n" printf("%s", qPrintable(app.tr("%1\n"
"Usage: %s [--device=\"/device/path\"] [--notray|--force-tray] [\"layout name\"]\n" "Usage: %2 [--device=\"/device/path\"] [--notray|--force-tray] [\"layout name\"]\n"
"\n" "\n"
"Options:\n" "Options:\n"
" -h, --help Print this help message.\n" " -h, --help Print this help message.\n"
@ -108,15 +109,16 @@ int main( int argc, char **argv )
" list of devices and layouts.\n" " list of devices and layouts.\n"
" \"layout name\" Load the given layout in an already running\n" " \"layout name\" Load the given layout in an already running\n"
" instance of QJoyPad, or start QJoyPad using the\n" " instance of QJoyPad, or start QJoyPad using the\n"
" given layout.\n", QJOYPAD_NAME, argc > 0 ? argv[0] : "qjoypad"); " given layout.\n").arg(QJOYPAD_NAME, argc > 0 ? argv[0] : "qjoypad")));
return 0; return 0;
case 'd': case 'd':
if (QFile::exists(optarg)) { if (QFileInfo(optarg).isDir()) {
devdir = optarg; devdir = optarg;
} }
else { else {
fprintf(stderr, "No such file or directory: %s\n", optarg); errorBox(app.tr("Not a directory"),
app.tr("Path is not a directory: %1").arg(optarg));
return 1; return 1;
} }
break; break;
@ -188,15 +190,18 @@ int main( int argc, char **argv )
//then prevent two instances from running at once. //then prevent two instances from running at once.
//however, if we are setting the layout or updating the device //however, if we are setting the layout or updating the device
//list, this is not an error and we shouldn't make one! //list, this is not an error and we shouldn't make one!
if (layout.isEmpty() && update == false) if (layout.isEmpty() && !update)
errorBox("Instance Error","There is already a running instance of QJoyPad; please close\nthe old instance before starting a new one."); errorBox(app.tr("Instance Error"),
app.tr("There is already a running instance of QJoyPad; please close\nthe old instance before starting a new one."));
else { else {
//if one of these is the case, send the approrpriate signal! //if one of these is the case, send the approrpriate signal!
if (update == true) if (update) {
kill(pid,SIGUSR1); kill(pid,SIGUSR1);
if (!layout.isEmpty()) }
if (!layout.isEmpty()) {
kill(pid,SIGUSR2); kill(pid,SIGUSR2);
} }
}
//and quit. We don't need two instances. //and quit. We don't need two instances.
return 0; return 0;
} }
@ -211,12 +216,13 @@ int main( int argc, char **argv )
if (forceTrayIcon) { if (forceTrayIcon) {
int sleepCounter = 0; int sleepCounter = 0;
while(!QSystemTrayIcon::isSystemTrayAvailable()) { while (!QSystemTrayIcon::isSystemTrayAvailable()) {
sleep(1); sleep(1);
sleepCounter++; sleepCounter++;
if(sleepCounter > 20) { if (sleepCounter > 20) {
printf("Error, we've waited more than 20 seconds, your sys tray probably isn't loading\n"); errorBox(app.tr("System tray isn't loading"),
exit(1); app.tr("Waited more than 20 seconds for the system tray to load. Giving up."));
return 1;
} }
} }
} }

View File

@ -6,15 +6,15 @@ QuickSet::QuickSet( JoyPad* jp, QWidget *parent)
: QDialog(parent) { : QDialog(parent) {
setting = false; setting = false;
joypad = jp; joypad = jp;
setWindowTitle("Set " + jp->getName()); setWindowTitle(tr("Set %1").arg(jp->getName()));
QVBoxLayout* LMain = new QVBoxLayout(this); QVBoxLayout* LMain = new QVBoxLayout(this);
LMain->setMargin(5); LMain->setMargin(5);
LMain->setSpacing(5); LMain->setSpacing(5);
//LMain->setAutoAdd(true); //LMain->setAutoAdd(true);
QLabel *temp = new QLabel("Press any button or axis and\nyou will be prompted for a key.",this); QLabel *temp = new QLabel(tr("Press any button or axis and\nyou will be prompted for a key."),this);
LMain->addWidget(temp); LMain->addWidget(temp);
QPushButton* button = new QPushButton("Done",this); QPushButton* button = new QPushButton(tr("Done"),this);
LMain->addWidget(button); LMain->addWidget(button);
connect( button, SIGNAL(clicked()), this, SLOT(accept())); connect( button, SIGNAL(clicked()), this, SLOT(accept()));
} }
@ -35,13 +35,15 @@ void QuickSet::jsevent(const js_event &msg ) {
setting = false; setting = false;
//if a mouse button was used, //if a mouse button was used,
if (code > MOUSE_OFFSET) if (code > MOUSE_OFFSET) {
//then tell it to the Button a mouse button //then tell it to the Button a mouse button
button->setKey(true, code - MOUSE_OFFSET); button->setKey(true, code - MOUSE_OFFSET);
else }
else {
//otherwise, tell it to use a keycode. //otherwise, tell it to use a keycode.
button->setKey(false, code); button->setKey(false, code);
} }
}
else if (type == JS_EVENT_AXIS) { else if (type == JS_EVENT_AXIS) {
//require a signal strength of at least 5000 to consider an axis moved. //require a signal strength of at least 5000 to consider an axis moved.
if (abs(msg.value) < 5000) return; if (abs(msg.value) < 5000) return;
@ -51,7 +53,7 @@ void QuickSet::jsevent(const js_event &msg ) {
//grab a keycode for that axis and that direction //grab a keycode for that axis and that direction
setting = true; setting = true;
int code = GetKey(QString("%1, %2").arg(axis->getName(), msg.value > 0 ? "positive" : "negative"), false).exec(); int code = GetKey((msg.value >= 0 ? tr("%1, positive") : tr("%1, negative")).arg(axis->getName()), false).exec();
setting = false; setting = false;
//assign the key to the axis. //assign the key to the axis.