Example #1
0
MainWindow::MainWindow(QHash<int, Joystick*> *joysticks, CommandLineUtility *cmdutility, bool graphical, QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->stackedWidget->setCurrentIndex(0);

    delete ui->tab_2;
    ui->tab_2 = 0;

    delete ui->tab;
    ui->tab = 0;

    this->graphical = graphical;
    signalDisconnect = false;
    showTrayIcon = !cmdutility->isTrayHidden() && graphical;

    this->joysticks = joysticks;

    if (showTrayIcon)
    {
        trayIconMenu = new QMenu(this);
        trayIcon = new QSystemTrayIcon(this);
        connect(trayIconMenu, SIGNAL(aboutToShow()), this, SLOT(refreshTrayIconMenu()));
        connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconClickAction(QSystemTrayIcon::ActivationReason)), Qt::DirectConnection);
    }

    fillButtons(joysticks);
    if (cmdutility->hasProfile())
    {
        if (cmdutility->hasControllerNumber())
        {
            loadConfigFile(cmdutility->getProfileLocation(), cmdutility->getControllerNumber());
        }
        else
        {
            loadConfigFile(cmdutility->getProfileLocation());
        }
    }

    aboutDialog = new AboutDialog(this);

    QApplication *app = static_cast<QApplication*> (QCoreApplication::instance());
    connect(ui->menuOptions, SIGNAL(aboutToShow()), this, SLOT(mainMenuChange()));
    connect(ui->actionAbout_Qt, SIGNAL(triggered()), app, SLOT(aboutQt()));
}
Example #2
0
MainWindow::MainWindow(QMap<SDL_JoystickID, InputDevice*> *joysticks, CommandLineUtility *cmdutility, AntiMicroSettings *settings, bool graphical, QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->stackedWidget->setCurrentIndex(0);

    //delete ui->tab_2;
    //ui->tab_2 = 0;

    //delete ui->tab;
    //ui->tab = 0;

    this->translator = 0;
    this->cmdutility = cmdutility;
    this->graphical = graphical;
    this->settings = settings;

    ui->actionStick_Pad_Assign->setVisible(false);

#ifndef USE_SDL_2
    ui->actionGameController_Mapping->setVisible(false);
#endif

#ifdef Q_OS_UNIX
    #if defined(USE_SDL_2) && defined(WITH_X11)
        #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
    if (QApplication::platformName() == QStringLiteral("xcb"))
    {
        #endif
    this->appWatcher = new AutoProfileWatcher(settings, this);
    checkAutoProfileWatcherTimer();
        #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
    }
    else
    {
        this->appWatcher = 0;
    }
        #endif
    #endif
#elif defined(Q_OS_WIN)
    this->appWatcher = new AutoProfileWatcher(settings, this);
    checkAutoProfileWatcherTimer();
#else
    this->appWatcher = 0;
#endif

    signalDisconnect = false;
    showTrayIcon = !cmdutility->isTrayHidden() && graphical &&
                   !cmdutility->shouldListControllers() && !cmdutility->shouldMapController();

    this->joysticks = joysticks;

    if (showTrayIcon)
    {
        trayIconMenu = new QMenu(this);
        trayIcon = new QSystemTrayIcon(this);
        connect(trayIconMenu, SIGNAL(aboutToShow()), this, SLOT(refreshTrayIconMenu()));
        connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconClickAction(QSystemTrayIcon::ActivationReason)), Qt::DirectConnection);
    }

    // Look at flags and call setEnabled as desired; defaults to true.
    // enabled status is used to specify whether errors
    // in profile loading and saving should be
    // display in a window or written to stderr.
    if (graphical)
    {
        if (cmdutility->isHiddenRequested() && cmdutility->isTrayHidden())
        {
            setEnabled(false);
        }
    }
    else
    {
        setEnabled(false);
    }

    fillButtons(joysticks);
    if (cmdutility->hasProfile())
    {
        if (cmdutility->hasControllerNumber())
        {
            loadConfigFile(cmdutility->getProfileLocation(), cmdutility->getControllerNumber());
        }
        else if (cmdutility->hasControllerID())
        {
            loadConfigFile(cmdutility->getProfileLocation(), cmdutility->hasControllerID());
        }
        else
        {
            loadConfigFile(cmdutility->getProfileLocation());
        }
    }
    else if (cmdutility->isUnloadRequested())
    {
        if (cmdutility->hasControllerNumber())
        {
            unloadCurrentConfig(cmdutility->getControllerNumber());
        }
        else if (cmdutility->hasControllerID())
        {
            unloadCurrentConfig(cmdutility->hasControllerID());
        }
        else
        {
            unloadCurrentConfig(0);
        }
    }
    else if (cmdutility->getStartSetNumber() > 0)
    {
        if (cmdutility->hasControllerNumber())
        {
            changeStartSetNumber(cmdutility->getJoyStartSetNumber(), cmdutility->getControllerNumber());
        }
        else if (cmdutility->hasControllerID())
        {
            changeStartSetNumber(cmdutility->getJoyStartSetNumber(), cmdutility->getControllerID());
        }
        else
        {
            changeStartSetNumber(cmdutility->getJoyStartSetNumber());
        }
    }
    else if (cmdutility->shouldListControllers())
    {
        graphical = false;
    }
#ifdef USE_SDL_2
    else if (cmdutility->shouldMapController())
    {
        graphical = false;
        if (cmdutility->hasControllerNumber())
        {
            unsigned int joypadIndex = cmdutility->getControllerNumber();
            selectControllerJoyTab(joypadIndex);
            openGameControllerMappingWindow(true);
        }
        else if (cmdutility->hasControllerID())
        {
            QString joypadGUID = cmdutility->getControllerID();
            selectControllerJoyTab(joypadGUID);
            openGameControllerMappingWindow(true);
        }
    }
#endif

    resize(settings->value("WindowSize", size()).toSize());
    move(settings->value("WindowPosition", pos()).toPoint());

    aboutDialog = new AboutDialog(this);

#ifdef Q_OS_WIN
    bool shouldAssociateProfiles = settings->value("AssociateProfiles", true).toBool();

    if (!WinInfo::containsFileAssociationinRegistry() && shouldAssociateProfiles)
    {
        QMessageBox msg;
        msg.setWindowTitle(tr("File Association"));
        msg.setText(tr("No file association was found for .amgp files. Would you like to associate AntiMicro with .amgp files?"));
        msg.setModal(true);
        msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
        int result = msg.exec();
        if (result == QMessageBox::Yes)
        {
            WinInfo::writeFileAssocationToRegistry();
            settings->setValue("AssociateProfiles", 1);
        }
        else
        {
            settings->setValue("AssociateProfiles", 0);
        }
    }
#endif

    connect(ui->menuOptions, SIGNAL(aboutToShow()), this, SLOT(mainMenuChange()));
    connect(ui->actionKeyValue, SIGNAL(triggered()), this, SLOT(openKeyCheckerDialog()));
    connect(ui->actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
    connect(ui->actionProperties, SIGNAL(triggered()), this, SLOT(openJoystickStatusWindow()));
    connect(ui->actionGitHubPage, SIGNAL(triggered()), this, SLOT(openGitHubPage()));
    connect(ui->actionOptions, SIGNAL(triggered()), this, SLOT(openMainSettingsDialog()));
    connect(ui->actionWiki, SIGNAL(triggered()), this, SLOT(openWikiPage()));

#ifdef USE_SDL_2
    connect(ui->actionGameController_Mapping, SIGNAL(triggered()), this, SLOT(openGameControllerMappingWindow()));
    //connect(ui->menuOptions, SIGNAL(aboutToShow()), this, SLOT(updateMenuOptions()));
    #if defined(Q_OS_UNIX) && defined(WITH_X11)
        #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
    if (QApplication::platformName() == QStringLiteral("xcb"))
    {
        #endif
    connect(appWatcher, SIGNAL(foundApplicableProfile(AutoProfileInfo*)), this, SLOT(autoprofileLoad(AutoProfileInfo*)));
        #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
    }