BaseInstance::BaseInstance(BaseInstancePrivate *d_in, const QString &rootDir, SettingsObject *settings_obj, QObject *parent) : QObject(parent), inst_d(d_in) { I_D(BaseInstance); d->m_settings = std::shared_ptr<SettingsObject>(settings_obj); d->m_rootDir = rootDir; settings().registerSetting("name", "Unnamed Instance"); settings().registerSetting("iconKey", "default"); connect(MMC->icons().get(), SIGNAL(iconUpdated(QString)), SLOT(iconUpdated(QString))); settings().registerSetting("notes", ""); settings().registerSetting("lastLaunchTime", 0); /* * custom base jar has no default. it is determined in code... see the accessor methods for *it * * for instances that DO NOT have the CustomBaseJar setting (legacy instances), * [.]minecraft/bin/mcbackup.jar is the default base jar */ settings().registerSetting("UseCustomBaseJar", true); settings().registerSetting("CustomBaseJar", ""); auto globalSettings = MMC->settings(); // Java Settings settings().registerSetting("OverrideJava", false); settings().registerSetting("OverrideJavaLocation", false); settings().registerSetting("OverrideJavaArgs", false); settings().registerOverride(globalSettings->getSetting("JavaPath")); settings().registerOverride(globalSettings->getSetting("JvmArgs")); // Custom Commands settings().registerSetting({"OverrideCommands","OverrideLaunchCmd"}, false); settings().registerOverride(globalSettings->getSetting("PreLaunchCommand")); settings().registerOverride(globalSettings->getSetting("PostExitCommand")); // Window Size settings().registerSetting("OverrideWindow", false); settings().registerOverride(globalSettings->getSetting("LaunchMaximized")); settings().registerOverride(globalSettings->getSetting("MinecraftWinWidth")); settings().registerOverride(globalSettings->getSetting("MinecraftWinHeight")); // Memory settings().registerSetting("OverrideMemory", false); settings().registerOverride(globalSettings->getSetting("MinMemAlloc")); settings().registerOverride(globalSettings->getSetting("MaxMemAlloc")); settings().registerOverride(globalSettings->getSetting("PermGen")); // Console settings().registerSetting("OverrideConsole", false); settings().registerOverride(globalSettings->getSetting("ShowConsole")); settings().registerOverride(globalSettings->getSetting("AutoCloseConsole")); settings().registerOverride(globalSettings->getSetting("LogPrePostOutput")); }
void IconList::fileChanged(const QString &path) { QLOG_INFO() << "Checking " << path; QFileInfo checkfile(path); if (!checkfile.exists()) return; QString key = checkfile.baseName(); int idx = getIconIndex(key); if (idx == -1) return; QIcon icon(path); if (!icon.availableSizes().size()) return; icons[idx].m_images[MMCIcon::FileBased].icon = icon; dataChanged(index(idx), index(idx)); emit iconUpdated(key); }
void StatusIcon::setIcon(const KaduIcon &icon) { Icon = icon; emit iconUpdated(Icon); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { MultiMCPlatform::fixWM_CLASS(this); ui->setupUi(this); QString winTitle = QString("MultiMC 5 - Version %1").arg(BuildConfig.printableVersionString()); if (!BuildConfig.BUILD_PLATFORM.isEmpty()) winTitle += " on " + BuildConfig.BUILD_PLATFORM; setWindowTitle(winTitle); // OSX magic. // setUnifiedTitleAndToolBarOnMac(true); // Global shortcuts { //FIXME: This is kinda weird. and bad. We need some kind of managed shutdown. auto q = new QShortcut(QKeySequence::Quit, this); connect(q, SIGNAL(activated()), qApp, SLOT(quit())); } // The instance action toolbar customizations { // disabled until we have an instance selected ui->instanceToolBar->setEnabled(false); // the rename label is inside the rename tool button renameButton = new LabeledToolButton(); renameButton->setText("Instance Name"); renameButton->setToolTip(ui->actionRenameInstance->toolTip()); connect(renameButton, SIGNAL(clicked(bool)), SLOT(on_actionRenameInstance_triggered())); ui->instanceToolBar->insertWidget(ui->actionLaunchInstance, renameButton); ui->instanceToolBar->insertSeparator(ui->actionLaunchInstance); renameButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); } // Add the news label to the news toolbar. { newsLabel = new QToolButton(); newsLabel->setIcon(QIcon::fromTheme("news")); newsLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); newsLabel->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); ui->newsToolBar->insertWidget(ui->actionMoreNews, newsLabel); QObject::connect(newsLabel, &QAbstractButton::clicked, this, &MainWindow::newsButtonClicked); QObject::connect(MMC->newsChecker().get(), &NewsChecker::newsLoaded, this, &MainWindow::updateNewsLabel); updateNewsLabel(); } // Create the instance list widget { view = new GroupView(ui->centralWidget); view->setSelectionMode(QAbstractItemView::SingleSelection); // view->setCategoryDrawer(drawer); // view->setCollapsibleBlocks(true); // view->setViewMode(QListView::IconMode); // view->setFlow(QListView::LeftToRight); // view->setWordWrap(true); // view->setMouseTracking(true); // view->viewport()->setAttribute(Qt::WA_Hover); auto delegate = new ListViewDelegate(); view->setItemDelegate(delegate); // view->setSpacing(10); // view->setUniformItemWidths(true); // do not show ugly blue border on the mac view->setAttribute(Qt::WA_MacShowFocusRect, false); view->installEventFilter(this); proxymodel = new InstanceProxyModel(this); // proxymodel->setSortRole(KCategorizedSortFilterProxyModel::CategorySortRole); // proxymodel->setFilterRole(KCategorizedSortFilterProxyModel::CategorySortRole); // proxymodel->setDynamicSortFilter ( true ); // FIXME: instList should be global-ish, or at least not tied to the main window... // maybe the application itself? proxymodel->setSourceModel(MMC->instances().get()); proxymodel->sort(0); view->setFrameShape(QFrame::NoFrame); view->setModel(proxymodel); view->setContextMenuPolicy(Qt::CustomContextMenu); connect(view, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(showInstanceContextMenu(const QPoint &))); ui->horizontalLayout->addWidget(view); } // The cat background { bool cat_enable = MMC->settings()->get("TheCat").toBool(); ui->actionCAT->setChecked(cat_enable); connect(ui->actionCAT, SIGNAL(toggled(bool)), SLOT(onCatToggled(bool))); setCatBackground(cat_enable); } // start instance when double-clicked connect(view, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(instanceActivated(const QModelIndex &))); // track the selection -- update the instance toolbar connect(view->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(instanceChanged(const QModelIndex &, const QModelIndex &))); // track icon changes and update the toolbar! connect(MMC->icons().get(), SIGNAL(iconUpdated(QString)), SLOT(iconUpdated(QString))); // model reset -> selection is invalid. All the instance pointers are wrong. // FIXME: stop using POINTERS everywhere connect(MMC->instances().get(), SIGNAL(dataIsInvalid()), SLOT(selectionBad())); m_statusLeft = new QLabel(tr("No instance selected"), this); m_statusRight = new ServerStatus(this); statusBar()->addPermanentWidget(m_statusLeft, 1); statusBar()->addPermanentWidget(m_statusRight, 0); // Add "manage accounts" button, right align QWidget *spacer = new QWidget(); spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); ui->mainToolBar->addWidget(spacer); accountMenu = new QMenu(this); manageAccountsAction = new QAction(tr("Manage Accounts"), this); manageAccountsAction->setCheckable(false); connect(manageAccountsAction, SIGNAL(triggered(bool)), this, SLOT(on_actionManageAccounts_triggered())); repopulateAccountsMenu(); accountMenuButton = new QToolButton(this); accountMenuButton->setText(tr("Accounts")); accountMenuButton->setMenu(accountMenu); accountMenuButton->setPopupMode(QToolButton::InstantPopup); accountMenuButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); accountMenuButton->setIcon(QIcon::fromTheme("noaccount")); QWidgetAction *accountMenuButtonAction = new QWidgetAction(this); accountMenuButtonAction->setDefaultWidget(accountMenuButton); ui->mainToolBar->addAction(accountMenuButtonAction); // Update the menu when the active account changes. // Shouldn't have to use lambdas here like this, but if I don't, the compiler throws a fit. // Template hell sucks... connect(MMC->accounts().get(), &MojangAccountList::activeAccountChanged, [this] { activeAccountChanged(); }); connect(MMC->accounts().get(), &MojangAccountList::listChanged, [this] { repopulateAccountsMenu(); }); // Show initial account activeAccountChanged(); auto accounts = MMC->accounts(); QList<CacheDownloadPtr> skin_dls; for (int i = 0; i < accounts->count(); i++) { auto account = accounts->at(i); if (account != nullptr) { for (auto profile : account->profiles()) { auto meta = MMC->metacache()->resolveEntry("skins", profile.name + ".png"); auto action = CacheDownload::make( QUrl("http://" + URLConstants::SKINS_BASE + profile.name + ".png"), meta); skin_dls.append(action); meta->stale = true; } } } if(!skin_dls.isEmpty()) { auto job = new NetJob("Startup player skins download"); connect(job, SIGNAL(succeeded()), SLOT(skinJobFinished())); connect(job, SIGNAL(failed()), SLOT(skinJobFinished())); for(auto action: skin_dls) job->addNetAction(action); skin_download_job.reset(job); job->start(); } // run the things that load and download other things... FIXME: this is NOT the place // FIXME: invisible actions in the background = NOPE. { if (!MMC->minecraftlist()->isLoaded()) { m_versionLoadTask = MMC->minecraftlist()->getLoadTask(); startTask(m_versionLoadTask); } if (!MMC->lwjgllist()->isLoaded()) { MMC->lwjgllist()->loadList(); } MMC->newsChecker()->reloadNews(); updateNewsLabel(); // set up the updater object. auto updater = MMC->updateChecker(); connect(updater.get(), &UpdateChecker::updateAvailable, this, &MainWindow::updateAvailable); connect(updater.get(), &UpdateChecker::noUpdateFound, [this]() { CustomMessageBox::selectable( this, tr("No update found."), tr("No MultiMC update was found!\nYou are using the latest version."))->exec(); }); // if automatic update checks are allowed, start one. if (MMC->settings()->get("AutoUpdate").toBool()) on_actionCheckUpdate_triggered(); connect(MMC->notificationChecker().get(), &NotificationChecker::notificationCheckFinished, this, &MainWindow::notificationsChanged); } setSelectedInstanceById(MMC->settings()->get("SelectedInstance").toString()); // removing this looks stupid view->setFocus(); }
void IconList::directoryChanged(const QString &path) { QDir new_dir (path); if(m_dir.absolutePath() != new_dir.absolutePath()) { m_dir.setPath(path); m_dir.refresh(); if(is_watching) stopWatching(); startWatching(); } if(!m_dir.exists()) if(!ensureFolderPathExists(m_dir.absolutePath())) return; m_dir.refresh(); auto new_list = m_dir.entryList(QDir::Files, QDir::Name); for (auto it = new_list.begin(); it != new_list.end(); it++) { QString &foo = (*it); foo = m_dir.filePath(foo); } auto new_set = new_list.toSet(); QList<QString> current_list; for (auto &it : icons) { if (!it.has(MMCIcon::FileBased)) continue; current_list.push_back(it.m_images[MMCIcon::FileBased].filename); } QSet<QString> current_set = current_list.toSet(); QSet<QString> to_remove = current_set; to_remove -= new_set; QSet<QString> to_add = new_set; to_add -= current_set; for (auto remove : to_remove) { QLOG_INFO() << "Removing " << remove; QFileInfo rmfile(remove); QString key = rmfile.baseName(); int idx = getIconIndex(key); if (idx == -1) continue; icons[idx].remove(MMCIcon::FileBased); if (icons[idx].type() == MMCIcon::ToBeDeleted) { beginRemoveRows(QModelIndex(), idx, idx); icons.remove(idx); reindex(); endRemoveRows(); } else { dataChanged(index(idx), index(idx)); } m_watcher->removePath(remove); emit iconUpdated(key); } for (auto add : to_add) { QLOG_INFO() << "Adding " << add; QFileInfo addfile(add); QString key = addfile.baseName(); if (addIcon(key, QString(), addfile.filePath(), MMCIcon::FileBased)) { m_watcher->addPath(add); emit iconUpdated(key); } } }