Exemple #1
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    mSettings(new QSettings(this)),
    mSavePath(""),
    mProgressBar(new QProgressBar(this)),
    mStatusBar(new QStatusBar(this)),
    mToolBar(new QToolBar(this)),
    mMenuBar(new QMenuBar(this)),
    mTabWidget(new QTabWidget(this)),

    // Menus
    mFileMenu(new QMenu(tr("File"), this)),
    mEditMenu(new QMenu(tr("Edit"), this)),
    mToolsMenu(new QMenu(tr("Tools"), this)),
    mHelpMenu(new QMenu(tr("Help"), this)),

    //Actions
    mActionExit(new QAction(QP_ICON("application-exit"), tr("Exit"), this)),
    mActionOpen(new QAction(QP_ICON("document-open"),tr("Open"), this)),
    mActionSave(new QAction(QP_ICON("document-save"),tr("Save"), this)),
    mActionSaveAs(new QAction(QP_ICON("document-save-as"),tr("Save As"), this)),
    mActionPrint(new QAction(QP_ICON("document-print"),tr("Print"), this)),

    mActionClear(new QAction(QP_ICON("edit-clear"), tr("Clear"), this)),
    mActionUndo(new QAction(QP_ICON("edit-undo"),tr("Undo"), this)),
    mActionRedo(new QAction(QP_ICON("edit-redo"),tr("Redo"), this)),
    mActionSwap(new QAction(QP_ICON("system-switch-user"), tr("Swap"), this)),
    mActionOptions(new QAction(QP_ICON("configure"), tr("Options"), this)),

    mActionAbout(new QAction(QIcon::fromTheme("help-about"), tr("About"), this)),
    mActionAboutQt(new QAction(tr("About Qt"), this)),

    mTranslationWidget(new QPTranslationWidget(this)),
    mDictionaryWidget(new DictionaryWidget(this)),
    mSettingsDialog(new Config(this)),

    mPluginsConfig(new PluginsConfig),
    mTranslatorsConfig(new QPTranslatorsConfig(this)),
    mLanguageConfig(new LanguageConfig(this)),
    mDictionaryConfig(new DictionaryConfig(this)),
    mCommonConfig(new CommonConfig(this))
{
    setWindowTitle(qApp->applicationName());

    mActionOpen->setShortcut(QKeySequence("Ctrl+O"));
    mActionSave->setShortcut(QKeySequence("Ctrl+S"));
    mActionSaveAs->setShortcut(QKeySequence("Ctrl+Shift+S"));
    mActionPrint->setShortcut(QKeySequence("Ctrl+P"));
    mActionExit->setShortcut(QKeySequence("Ctrl+Q"));

    mActionUndo->setShortcut(QKeySequence("Ctrl+U"));
    mActionRedo->setShortcut(QKeySequence("Ctrl+R"));
    mActionSwap->setShortcut(QKeySequence("Ctrl+Alt+S"));

    mFileMenu->addAction(mActionOpen);
    mFileMenu->addSeparator();
    mFileMenu->addAction(mActionSave);
    mFileMenu->addAction(mActionSaveAs);
    mFileMenu->addAction(mActionPrint);
    mFileMenu->addSeparator();
    mFileMenu->addAction(mActionExit);

    mEditMenu->addAction(mActionClear);
    mEditMenu->addSeparator();
    mEditMenu->addAction(mActionUndo);
    mEditMenu->addAction(mActionRedo);
    mEditMenu->addAction(mActionSwap);
    mEditMenu->addSeparator();
    mEditMenu->addAction(mActionOptions);

    mHelpMenu->addAction(mActionAbout);
    mHelpMenu->addAction(mActionAboutQt);

    mMenuBar->addMenu(mFileMenu);
    mMenuBar->addMenu(mEditMenu);
    mMenuBar->addMenu(mHelpMenu);

    mToolBar->addAction(mActionOpen);
    mToolBar->addAction(mActionSave);
    mToolBar->addAction(mActionSaveAs);
    mToolBar->addSeparator();
    mToolBar->addAction(mActionClear);
    mToolBar->addAction(mActionUndo);
    mToolBar->addAction(mActionRedo);
    mToolBar->setMovable(false);

    mTabWidget->setTabPosition(QTabWidget::West);

    this->setCentralWidget(mTabWidget);
    this->setStatusBar(mStatusBar);
    this->setMenuBar(mMenuBar);

    mProgressBar->setMaximum(0);
    mProgressBar->setMinimum(0);
    mProgressBar->setValue(0);
    mStatusBar->addPermanentWidget(mProgressBar);

    mProgressBar->setFormat("");
    mProgressBar->setFixedWidth(200);
    stopProgressBar();

    this->addToolBar(mToolBar);
    this->addToolBar(mDictionaryWidget->getToolBar());
    this->addToolBar(mTranslationWidget->mainToolBar());

    mTabWidget->insertTab(mTabWidget->count(), mTranslationWidget, QP_ICON("translator"), tr("Translator"));
    mTabWidget->insertTab(mTabWidget->count(), mDictionaryWidget, QP_ICON("dictionary"), tr("Dictionary"));

    if(mTabWidget->count() > 1)
        mTabWidget->setCurrentIndex(0);

    // Configuring settings pages
    mSettingsDialog->addPage(mTranslatorsConfig, "Translators");
    mSettingsDialog->addPage(mDictionaryConfig, "Dictionaries");
    mSettingsDialog->addPage(mLanguageConfig, "Languages");
    mSettingsDialog->addPage(mPluginsConfig, "Plugins");
    mSettingsDialog->addPage(mCommonConfig, "Generic");

    connect(mActionOpen, SIGNAL(triggered()), this, SLOT(open()));
    connect(mActionPrint, SIGNAL(triggered()), this, SLOT(print()));
    connect(mActionSave, SIGNAL(triggered()), this, SLOT(save()));
    connect(mActionSaveAs, SIGNAL(triggered()), this, SLOT(saveAs()));

    connect(mActionExit, SIGNAL(triggered()), this, SLOT(exit()));
    connect(mActionClear, SIGNAL(triggered()), this, SLOT(clear()));
    connect(mActionUndo, SIGNAL(triggered()), this, SLOT(undo()));
    connect(mActionRedo, SIGNAL(triggered()), this, SLOT(redo()));
    connect(mActionSwap, SIGNAL(triggered()), mTranslationWidget, SLOT(swap()));
    connect(mActionOptions, SIGNAL(triggered()), mSettingsDialog, SLOT(show()));
    connect(mActionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
    connect(mActionAbout, SIGNAL(triggered()), this, SLOT(about()));

    // Widgets , Dialogs, etc
    connect(mSettingsDialog, SIGNAL(accepted()), this, SLOT(onConfigAccept()));
    connect(mTabWidget, SIGNAL(currentChanged(int)), this, SLOT(onIndexChange(int)));

    connect(mTranslatorsConfig, SIGNAL(translatorIndexChanged(int)), mTranslationWidget, SLOT(setTranslatorIndex(int)));
    connect(mTranslationWidget, SIGNAL(translatorIndexChanged(int)), mTranslatorsConfig, SLOT(setTranslatorIndex(int)));
    connect(mTranslationWidget, SIGNAL(translatorIndexChanged(int)), this, SLOT(updateTranslatorConfig()));

    connect(mTranslationWidget, SIGNAL(message(QString)), this, SLOT(setStatusBarMessage(QString)));
    connect(mDictionaryWidget, SIGNAL(message(QString)), this, SLOT(setStatusBarMessage(QString)));

    connect(mTranslationWidget, SIGNAL(started()), this, SLOT(startProgressBar()));
    connect(mDictionaryWidget, SIGNAL(started()), this, SLOT(startProgressBar()));

    connect(mTranslationWidget, SIGNAL(finished()), this, SLOT(stopProgressBar()));
    connect(mDictionaryWidget, SIGNAL(finished()), this, SLOT(stopProgressBar()));

    mSettings->beginGroup(QP_MAINWINDOW_CONFIG_GROUP);

    // Read configs
    updateTranslatorConfig();
    onConfigAccept();

    mTranslationWidget->setTranslatorsNames(mTranslatorsConfig->getTranslatorsNames());

    mTranslatorsConfig->read();

    readCfg();

}
Exemple #2
0
void clHttp::run()
{
    while(!closeThread) {
        sockHttp = socket(AF_INET,SOCK_STREAM,0);
#ifdef Q_OS_UNIX
        if(sockHttp == -1) {
#else
        if(sockHttp == INVALID_SOCKET) {
#endif
            debug.add(ERR, "Error creating socket");
            emit started(false);
            return;
        }
        int iBool = 1;
        if(setsockopt(sockHttp, SOL_SOCKET, SO_REUSEADDR, (char *)&iBool, sizeof(iBool)) != 0) {
#ifdef Q_OS_UNIX
            debug.add(ERR, "Error setsockopt: " + QString::fromLocal8Bit(strerror(errno)));
#else
            debug.add(ERR, "Error setsockopt: " + QString().setNum(WSAGetLastError()));
#endif
        }
#ifdef Q_OS_UNIX
        if(fcntl(sockHttp, F_SETFD, FD_CLOEXEC) == -1) { // Освобождает дискриптеры после закрытия сокета
            debug.add(ERR, "Error set FD_CLOEXEC socket: " + QString::fromLocal8Bit(strerror(errno)));
        }
#endif
        sockaddr_in local_addr;
        local_addr.sin_family = AF_INET;
        local_addr.sin_addr.s_addr = INADDR_ANY;
        local_addr.sin_port = htons(port);
        if(bind(sockHttp, (sockaddr *)&local_addr, sizeof(local_addr))) {
#ifdef Q_OS_UNIX
            debug.add(ERR, "Erorr bind port " + QString().setNum(port) + ": " + QString::fromLocal8Bit(strerror(errno)));
#else
            debug.add(ERR, "Erorr bind port "  + QString().setNum(port) + ": " + QString().setNum(WSAGetLastError()));
#endif
            closeHttpSocket();
            unsigned long time = 0;
            while(!closeThread && time < 3*1000) { msleep(200); time += 200; }
            continue;
        }
        if(listen(sockHttp, 10000) == -1) {
#ifdef Q_OS_UNIX
            debug.add(ERR, "Can't listen on port " + QString().setNum(port) + ": " + QString::fromLocal8Bit(strerror(errno)));
#else
            debug.add(ERR, "Can't listen on port " + QString().setNum(port) + ": " + QString().setNum(WSAGetLastError()));
#endif
            closeHttpSocket();
            unsigned long time = 0;
            while(!closeThread && time < 3*1000) { msleep(200); time += 200; }
            continue;
        }
        debug.add(NOTICE, "Started on port " + QString().setNum(htons(local_addr.sin_port)) +
                  " (id: " + QString().setNum((unsigned long)QThread::currentThreadId()) + ")");
        emit started(true);
        break;
    }
    //***********************
    fd_set readSet, errorSet;
    FD_ZERO(&readSet);
    FD_ZERO(&errorSet);
    FD_SET(sockHttp, &errorSet);
    FD_SET(sockHttp, &readSet);
    int SelectTiming = 0;
    //************************
    if ((SelectTiming = select(sockHttp+1, &readSet, 0, &errorSet, 0)) == -1) {
#ifdef Q_OS_UNIX
        debug.add(ERR, "Error on select accept: " + QString::fromLocal8Bit(strerror(errno)));
#else
        debug.add(ERR, "Error on select accept: " + QString().setNum(WSAGetLastError()));
#endif
        closeHttpSocket();
        emit started(false);
        return;
    }
    if(SelectTiming > 0) {
        if (FD_ISSET(sockHttp, &errorSet)) {
            debug.add(ERR, "Error connect server");
            closeHttpSocket();
            emit started(false);
            return;
        }
        if(FD_ISSET(sockHttp, &readSet)) {
            SOCKET client_socket;
            sockaddr_in client_addr;
            memset(&client_addr, 0, sizeof(sockaddr_in));
            while(!closeThread) {
                int client_addr_size = sizeof(client_addr);
#ifdef Q_OS_UNIX
                client_socket = accept(sockHttp, (sockaddr *)&client_addr, (socklen_t *)&client_addr_size);
#else
                client_socket = accept(sockHttp, (sockaddr *)&client_addr, &client_addr_size);
#endif
                if(client_socket > 0) {
                    processingHttp = new clProcessingHttp(client_socket);
                    connect(processingHttp, SIGNAL(disconnectClient(clProcessingHttp*)), this, SLOT(disconnectClient(clProcessingHttp*)));
                    connect(processingHttp, SIGNAL(request(clHtmlData*)), this, SIGNAL(request(clHtmlData*)));
                    connect(processingHttp, SIGNAL(error(QString,QString)), this, SIGNAL(error(QString,QString)));
                    mutex.lock();
                    listConnections.append(processingHttp);
                    mutex.unlock();
                    processingHttp->start();
                    memset(&client_addr, 0, sizeof(sockaddr_in));
                }
            }
        }
    }
Exemple #3
0
static int mainInternal(QApplication &a)
{
#ifdef MOBILE_DEVICE
	emugl = new MainUI();
	emugl->resize(pixel_xres, pixel_yres);
	emugl->showFullScreen();
#endif
	EnableFZ();
	// Disable screensaver
#ifdef __SYMBIAN32__
	QSystemScreenSaver ssObject(emugl);
	ssObject.setScreenSaverInhibit();
	QScopedPointer<SymbianMediaKeys> mediakeys(new SymbianMediaKeys());
#elif defined(QT_HAS_SYSTEMINFO)
	QScreenSaver ssObject(emugl);
	ssObject.setScreenSaverEnabled(false);
#endif

#ifdef QT_HAS_SDL
	SDLJoystick joy(true);
	joy.startEventLoop();
	SDL_Init(SDL_INIT_AUDIO);
	SDL_AudioSpec fmt, ret_fmt;
	memset(&fmt, 0, sizeof(fmt));
	fmt.freq = 44100;
	fmt.format = AUDIO_S16;
	fmt.channels = 2;
	fmt.samples = 2048;
	fmt.callback = &mixaudio;
	fmt.userdata = (void *)0;

	if (SDL_OpenAudio(&fmt, &ret_fmt) < 0) {
		ELOG("Failed to open audio: %s", SDL_GetError());
	} else {
		if (ret_fmt.samples != fmt.samples) // Notify, but still use it
			ELOG("Output audio samples: %d (requested: %d)", ret_fmt.samples, fmt.samples);
		if (ret_fmt.freq != fmt.freq || ret_fmt.format != fmt.format || ret_fmt.channels != fmt.channels) {
			ELOG("Sound buffer format does not match requested format.");
			ELOG("Output audio freq: %d (requested: %d)", ret_fmt.freq, fmt.freq);
			ELOG("Output audio format: %d (requested: %d)", ret_fmt.format, fmt.format);
			ELOG("Output audio channels: %d (requested: %d)", ret_fmt.channels, fmt.channels);
			ELOG("Provided output format does not match requirement, turning audio off");
			SDL_CloseAudio();
		}
	}

	// Audio must be unpaused _after_ NativeInit()
	SDL_PauseAudio(0);
#else
	QScopedPointer<QThread> thread(new QThread);
	QScopedPointer<MainAudio> audio(new MainAudio());
	audio->moveToThread(thread.data());
	QObject::connect(thread.data(), SIGNAL(started()), audio.data(), SLOT(run()));
	thread->start();
#endif
	int ret = a.exec();
#ifndef QT_HAS_SDL
	thread->terminate();
#endif
	return ret;
}
Exemple #4
0
void MainWindow::setUpApp()
{
	this->setLocalizationLanguage() ;
	m_ui = new Ui::MainWindow ;
	m_ui->setupUi( this ) ;

	this->setFixedSize( this->size() ) ;

	m_ui->tableWidget->setColumnWidth( 0,225 ) ;
	m_ui->tableWidget->setColumnWidth( 1,320 ) ;
	m_ui->tableWidget->setColumnWidth( 2,105 ) ;
	m_ui->tableWidget->hideColumn( 3 ) ;
	m_ui->tableWidget->setColumnWidth( 4,87 ) ;
	m_ui->tableWidget->setColumnWidth( 5,87 ) ;

#if QT_VERSION < QT_VERSION_CHECK( 5,0,0 )
	m_ui->tableWidget->verticalHeader()->setResizeMode( QHeaderView::ResizeToContents ) ;
#else
	m_ui->tableWidget->verticalHeader()->setSectionResizeMode( QHeaderView::ResizeToContents ) ;
#endif
	m_ui->tableWidget->verticalHeader()->setMinimumSectionSize( 30 ) ;

	this->setAcceptDrops( true ) ;
	this->setWindowIcon( QIcon( QString( ":/zuluMount.png" ) ) ) ;

	m_ui->tableWidget->setMouseTracking( true ) ;

	connect( m_ui->tableWidget,SIGNAL( itemEntered( QTableWidgetItem * ) ),this,SLOT( itemEntered( QTableWidgetItem * ) ) ) ;
	connect( m_ui->tableWidget,SIGNAL( currentItemChanged( QTableWidgetItem *,QTableWidgetItem * ) ),
		 this,SLOT( slotCurrentItemChanged( QTableWidgetItem *,QTableWidgetItem * ) ) ) ;
	connect( m_ui->pbmount,SIGNAL( clicked() ),this,SLOT( pbMount() ) ) ;
	connect( m_ui->pbupdate,SIGNAL( clicked()),this,SLOT(pbUpdate() ) ) ;
	connect( m_ui->pbclose,SIGNAL( clicked() ),this,SLOT( pbClose() ) ) ;
	connect( m_ui->tableWidget,SIGNAL( itemClicked( QTableWidgetItem * ) ),this,SLOT( itemClicked( QTableWidgetItem * ) ) ) ;

	this->setUpShortCuts() ;

	this->setUpFont() ;

	m_trayIcon = new QSystemTrayIcon( this ) ;
	m_trayIcon->setIcon( QIcon( QString( ":/zuluMount.png" ) ) ) ;

	QMenu * trayMenu = new QMenu( this ) ;

	m_autoMountAction = new QAction( this ) ;
	m_autoMount = this->autoMount() ;
	m_autoMountAction->setCheckable( true ) ;
	m_autoMountAction->setChecked( m_autoMount ) ;

	m_autoMountAction->setText( tr( "automount volumes" ) ) ;

	connect( m_autoMountAction,SIGNAL( toggled( bool ) ),this,SLOT( autoMountToggled( bool ) ) ) ;

	trayMenu->addAction( m_autoMountAction ) ;

	QAction * autoOpenFolderOnMount = new QAction( this ) ;
	autoOpenFolderOnMount->setCheckable( true ) ;
	m_autoOpenFolderOnMount = this->autoOpenFolderOnMount() ;
	autoOpenFolderOnMount->setChecked( m_autoOpenFolderOnMount ) ;
	autoOpenFolderOnMount->setText( tr( "auto open mount point" ) ) ;
	connect( autoOpenFolderOnMount,SIGNAL( toggled( bool ) ),this,SLOT( autoOpenFolderOnMount( bool ) ) ) ;

	trayMenu->addAction( autoOpenFolderOnMount ) ;

	trayMenu->addAction( tr( "quit" ),this,SLOT( pbClose() ) ) ;
	m_trayIcon->setContextMenu( trayMenu ) ;

	connect( m_trayIcon,SIGNAL( activated( QSystemTrayIcon::ActivationReason ) ),
		 this,SLOT( slotTrayClicked( QSystemTrayIcon::ActivationReason ) ) ) ;

	m_trayIcon->show() ;

	QString dirPath = QDir::homePath() + QString( "/.zuluCrypt/" ) ;
	QDir dir( dirPath ) ;

	if( !dir.exists() ){
		dir.mkdir( dirPath ) ;
	}

	Task * t = new Task() ;

	this->disableAll() ;

	connect( t,SIGNAL( signalMountedList( QStringList,QStringList ) ),
		 this,SLOT( slotMountedList( QStringList,QStringList ) ) ) ;
	connect( t,SIGNAL( done() ),this,SLOT( openVolumeFromArgumentList() ) ) ;
	connect( t,SIGNAL( done() ),this,SLOT( started() ) ) ;

	t->start( Task::Update ) ;

	this->startAutoMonitor() ;
}