void EditableFilterDialog::onWorkFinished(bool ok)
{
    setUiEnabled(true);
    if (ok)
    {
        emit applyFilter();
    }
}
void EditableFilterDialog::on__apply_clicked()
{
    setUiEnabled(false);

    _errorWidget->clean();
    _errorWidget->close();

    _model->apply(ui->_code->toPlainText());

}
void EditableFilterDialog::refreshCode()
{
    QString program = _model->readSourceFile();
    if (!program.isEmpty())
    {
        ui->_code->setPlainText(program);
    }
    else
    {
        setUiEnabled(false);
    }
}
void EditableFilterDialog::onBadConfiguration()
{
    setUiEnabled(true);
    configure();
}
Esempio n. 5
0
MainWindow::MainWindow(Eros *eros, QWidget *parent )
	: QMainWindow(parent)
{

	QFontDatabase::addApplicationFont(":/font/NotoSans-Regular");
	QFontDatabase::addApplicationFont(":/font/NotoSans-Bold");
	QFontDatabase::addApplicationFont(":/font/NotoSans-Italic");
	QFontDatabase::addApplicationFont(":/font/NotoSans-BoldItalic");
	QFontDatabase::addApplicationFont(":/font/Gobold");
	QFontDatabase::addApplicationFont(":/font/Gobold-bold");
	QFontDatabase::addApplicationFont(":/font/Gobold-thin");


	QFile version(":/data/version_info");
	if(!version.open(QIODevice::ReadOnly))
	{
		this->local_version_ = 1;
	}
	else
	{
		QByteArray data = version.readAll();
		QStringList tokens = QString::fromUtf8(data).split('|');
		this->local_version_ = tokens[0].toInt();
		version.close();
	}
	
	ui.setupUi(this);
	ui.centralWidget->setMouseTracking(true);
	this->setWindowTitle(tr("Alpha Version %1").arg(this->local_version_));

	setUiEnabled(false);
	this->eros_ = eros;
	this->config_ = new Config(this);
	this->connection_timer_ = new QTimer(this);
	this->matchmaking_timer_ = new QTimer(this);
	this->matchmaking_timer_->setInterval(500);
	this->matchmaking_start_ = new QTime();
	this->matchmaking_result_time_ = new QTime();
	this->long_process_start_time_ = new QTime();
	this->watcher_ = new DirectoryWatcher(this);
	this->watches_ = QList<DirectoryWatch*>();
	this->update_checker_nam_ = new QNetworkAccessManager(this);
	this->update_timer_ = new QTimer(this);
	this->long_process_timer_ = new QTimer(this);
	this->tray_icon_ = new QSystemTrayIcon(this);
	this->tray_icon_menu_ = new QMenu(this);
	this->preview_loader_nam_ = new QNetworkAccessManager(this);
	this->preview_cache_ = QMap<QString, QPixmap*>();
	this->upload_queue_ = QMap<QString, QTime*>();
	this->upload_queue_timer_ = new QTimer(this);

	tray_icon_action_show_ = new QAction("Hide Eros", this);
	tray_icon_action_close_ = new QAction("Close Eros", this);


	QObject::connect(tray_icon_action_show_, SIGNAL(triggered()), this, SLOT(toggleWindow()));
    QObject::connect(tray_icon_action_close_, SIGNAL(triggered()), qApp, SLOT(quit()));
	QObject::connect(this->tray_icon_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconClicked(QSystemTrayIcon::ActivationReason)));


	this->tray_icon_->setIcon(QIcon(":/img/client/icons/icon_32x32"));
	this->tray_icon_menu_->addAction(tray_icon_action_show_);
	this->tray_icon_menu_->addAction(tray_icon_action_close_);
	this->tray_icon_->setContextMenu(this->tray_icon_menu_);

#if !defined(Q_OS_MAC)
    title_bar_ = ErosTitleBar::addToLayout(this, ui.verticalLayout);
    title_bar_->setMenu(this->tray_icon_menu_);
#endif



	// File watcher
	QObject::connect(this->watcher_, SIGNAL(added(const QString &, const QString &)), this, SLOT(fileAdded(const QString &, const QString&)));

	// Update checker
	QObject::connect(update_checker_nam_, SIGNAL(finished(QNetworkReply*)), this, SLOT(updateCheckerFinished(QNetworkReply*)));
	QObject::connect(this->update_timer_, SIGNAL(timeout()), this, SLOT(updateCheckerTimerWorker()));

	//Preview loader
	QObject::connect(preview_loader_nam_, SIGNAL(finished(QNetworkReply*)), this, SLOT(previewDownloadFinished(QNetworkReply*)));

	// Set up Eros signals
	/// Eros Signals
	QObject::connect(eros_, SIGNAL(stateChanged(ErosState)), this, SLOT(erosStateChanged(ErosState)));
	QObject::connect(eros_, SIGNAL(connectionError(QAbstractSocket::SocketError, const QString)), this, SLOT(erosConnectionError(QAbstractSocket::SocketError, const QString)));
	QObject::connect(eros_, SIGNAL(connected()), this, SLOT(erosConnected()));
	QObject::connect(eros_, SIGNAL(disconnected()), this, SLOT(erosDisconnected()));
	QObject::connect(eros_, SIGNAL(authenticationFailed()), this, SLOT(erosAuthenticationFailed()));
	QObject::connect(eros_, SIGNAL(alreadyLoggedIn()), this, SLOT(erosAlreadyLoggedIn()));
	QObject::connect(eros_, SIGNAL(broadcastAlert(const QString, int)), this, SLOT(erosBroadcastAlert(const QString, int)));
	QObject::connect(eros_, SIGNAL(chatRoomAdded(ChatRoom*)), this, SLOT(erosChatRoomAdded(ChatRoom*)));
	QObject::connect(eros_, SIGNAL(chatRoomRemoved(ChatRoom*)), this, SLOT(erosChatRoomRemoved(ChatRoom*)));
	QObject::connect(eros_, SIGNAL(chatRoomJoined(ChatRoom*)), this, SLOT(erosChatRoomJoined(ChatRoom*)));
	QObject::connect(eros_, SIGNAL(chatRoomLeft(ChatRoom*)), this, SLOT(erosChatRoomLeft(ChatRoom*)));
	QObject::connect(eros_, SIGNAL(chatMessageReceieved(User*, const QString)), this, SLOT(erosChatMessageReceieved(User*, const QString)));
	QObject::connect(eros_, SIGNAL(localUserUpdated(LocalUser*)), this, SLOT(erosLocalUserUpdated(LocalUser*)));
	QObject::connect(eros_, SIGNAL(matchmakingStateChanged(ErosMatchmakingState)), this, SLOT(erosMatchmakingStateChanged(ErosMatchmakingState)));
	QObject::connect(eros_, SIGNAL(matchmakingMatchFound(MatchmakingMatch *)), this, SLOT(erosMatchmakingMatchFound(MatchmakingMatch *)));
	//QObject::connect(eros_, SIGNAL(regionStatsUpdated(ErosRegion, int)), this, SLOT(erosRegionStatsUpdated(ErosRegion, int)));
	QObject::connect(eros_, SIGNAL(statsUpdated(int, int)), this, SLOT(erosStatsUpdated(int, int)));
	QObject::connect(eros_, SIGNAL(replayUploadError(ErosError)), this, SLOT(erosReplayUploadError(ErosError)));
	QObject::connect(eros_, SIGNAL(replayUploaded()), this, SLOT(erosReplayUploaded()));
	QObject::connect(eros_, SIGNAL(uploadProgress(qint64, qint64)), this, SLOT(erosUploadProgress(qint64, qint64)));
	
	QObject::connect(eros_, SIGNAL(longProcessStateChanged(ErosLongProcessState)), this, SLOT(erosLongProcessStateChanged(ErosLongProcessState)));
	QObject::connect(eros_, SIGNAL(drawRequested()), this, SLOT(erosDrawRequested()));
	QObject::connect(eros_, SIGNAL(drawRequestFailed()), this, SLOT(erosDrawRequestFailed()));
	QObject::connect(eros_, SIGNAL(noShowRequested()), this, SLOT(erosNoShowRequested()));
	QObject::connect(eros_, SIGNAL(noShowRequestFailed()), this, SLOT(erosNoShowRequestFailed()));
	QObject::connect(eros_, SIGNAL(acknowledgeLongProcessFailed()), this, SLOT(erosAcknowledgeLongProcessFailed()));
	QObject::connect(eros_, SIGNAL(acknowledgedLongProcess()), this, SLOT(erosAcknowledgedLongProcess()));

	QObject::connect(eros_, SIGNAL(vetoesUpdated()), this, SLOT(erosVetoesUpdated()));
	QObject::connect(eros_, SIGNAL(toggleVetoFailed(Map*,ErosError)), this, SLOT(erosToggleVetoFailed(Map*,ErosError)));


	/// Eros Slots
	QObject::connect(this, SIGNAL(connectToEros(const QString, const QString, const QString)), eros_, SLOT(connectToEros(const QString, const QString, const QString)));
	QObject::connect(this, SIGNAL(disconnectFromEros()), eros_, SLOT(disconnectFromEros()));
	QObject::connect(ui.btnRefreshChats, SIGNAL(clicked()), eros_, SLOT(refreshChatRooms()));
	QObject::connect(this, SIGNAL(joinChatRoom(ChatRoom *, const QString)), eros_, SLOT(joinChatRoom(ChatRoom *, const QString)));
	QObject::connect(this, SIGNAL(leaveChatRoom(ChatRoom *)), eros_, SLOT(leaveChatRoom(ChatRoom *)));

	QObject::connect(this, SIGNAL(queueMatchmaking(ErosRegion, int)), eros_, SLOT(queueMatchmaking(ErosRegion, int)));
	QObject::connect(this, SIGNAL(queueMatchmaking(ErosRegionList, int)), eros_, SLOT(queueMatchmaking(ErosRegionList, int)));
	QObject::connect(this, SIGNAL(dequeueMatchmaking()), eros_, SLOT(dequeueMatchmaking()));
    QObject::connect(this, SIGNAL(forfeitMatchmaking()), eros_, SLOT(forfeitMatchmaking()));

	QObject::connect(this, SIGNAL(uploadReplay(QIODevice*)), eros_, SLOT(uploadReplay(QIODevice*)));
	QObject::connect(this, SIGNAL(uploadReplay(const QString)), eros_, SLOT(uploadReplay(const QString)));

	QObject::connect(this, SIGNAL(requestDraw()), eros_, SLOT(requestDraw()));
	QObject::connect(this, SIGNAL(requestNoShow()), eros_, SLOT(requestNoShow()));
	QObject::connect(this, SIGNAL(acknowledgeLongProcess(bool)), eros_, SLOT(acknowledgeLongProcess(bool)));

	QObject::connect(this, SIGNAL(toggleVeto(Map*)), eros_, SLOT(toggleVeto(Map*)));
	


	// timers
	QObject::connect(this->connection_timer_, SIGNAL(timeout()), this, SLOT(connectionTimerWorker()));
	QObject::connect(this->matchmaking_timer_, SIGNAL(timeout()), this, SLOT(matchmakingTimerWorker()));
	QObject::connect(this->long_process_timer_, SIGNAL(timeout()), this, SLOT(longProcessTimerWorker()));
	QObject::connect(this->upload_queue_timer_, SIGNAL(timeout()), this, SLOT(uploadTimerWorker()));

	this->long_process_timer_->setInterval(250);

	// UI Stuff
	settings_window_ = nullptr;
	bnetsettings_window_ = nullptr;

	// Remove the close box from the first 2 tabs.
    // On mac it's LeftSide. Assuming RightSide causes a nullptr.

	for (int i = 0; i < 3; i++)
	{
		QWidget *tab = ui.tabContainer->tabBar()->tabButton(i, QTabBar::RightSide);
		if (tab != nullptr)
			tab->resize(0, 0);

		tab = ui.tabContainer->tabBar()->tabButton(i, QTabBar::LeftSide);
		if (tab != nullptr)
			tab->resize(0, 0);
	}
    
	ui.tabContainer->tabBar()->setUsesScrollButtons(true);
	
	QObject::connect(ui.tabContainer, SIGNAL(tabCloseRequested(int)), this, SLOT(tabContainer_tabCloseRequested(int)));
	QObject::connect(ui.tabContainer, SIGNAL(currentChanged(int)), this, SLOT(tabContainer_currentChanged(int)));
	QObject::connect(ui.lblBottomMenu, SIGNAL(linkActivated(const QString &)), this, SLOT(label_linkActivated(const QString&)));
	QObject::connect(ui.btnJoinRoom, SIGNAL(clicked()), this, SLOT(btnJoinRoom_pressed()));
	QObject::connect(ui.lstChats, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(lstChats_currentItemChanged(QListWidgetItem *, QListWidgetItem *)));
	QObject::connect(ui.lstChats, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(lstChats_itemDoubleClicked(QListWidgetItem*)));
	QObject::connect(ui.cmbRegion, SIGNAL(currentIndexChanged(int)), this, SLOT(cmbRegion_currentIndexChanged(int)));
	QObject::connect(ui.cmbMapRegion, SIGNAL(currentIndexChanged(int)), this, SLOT(cmbMapRegion_currentIndexChanged(int)));
	QObject::connect(ui.btnQueue, SIGNAL(clicked()), this, SLOT(btnQueue_pressed()));
	QObject::connect(ui.btnDraw, SIGNAL(clicked()), this, SLOT(btnDraw_pressed()));
	QObject::connect(ui.btnNoShow, SIGNAL(clicked()), this, SLOT(btnNoShow_pressed()));
	QObject::connect(ui.lstMaps, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(lstMaps_currentItemChanged(QListWidgetItem *, QListWidgetItem *)));
	QObject::connect(ui.btnToggleVeto, SIGNAL(clicked()), this, SLOT(btnToggleVeto_clicked()));
	QObject::connect(ui.chkQueueRegion, SIGNAL(stateChanged(int)), this, SLOT(chkQueueRegion_stateChanged(int)));
#if !defined(Q_OS_MAC)
	this->tray_icon_->show();
#endif

		// The user should be prevented from emptying invalid values in the settings dialog.
	if (this->config_->profiles().count() == 0)
	{
		QMessageBox::information(this, "Eros", tr("Welcome to Eros! You need to configure some settings in order to continue. The settings window will now open."));
		openSettings();
	}
	else
	{
		this->connection_timer_->setInterval(500);
		this->connection_timer_->start();
	}

	QTimer::singleShot(0, this, SLOT(updateCheckerTimerWorker()));
	this->update_timer_->setInterval(1000 * 60 * 10);
	this->update_timer_->start();

	notification_sound_ = new QSound(":/sound/notification", this);
}