Exemplo n.º 1
0
QObject* LxDialogs::add( QString key,QString url )
{
	LxMainWindow* lxMain= lxCoreApp->getMainWin();
	LxBaseWin* lxDialog = new LxBaseWin(lxMain);

	QString strFullUrl;
	QFileInfo qFileInfo(url);
	if (isNetWorkPath(url) || qFileInfo.isAbsolute())
	{
		strFullUrl = url;
	}
	else
	{
		strFullUrl = QCoreApplication::applicationDirPath() +  QDir::separator() + url;
	}

    qDebug("LxDialogs::add(%s,%s);",key.toLocal8Bit().constData(), strFullUrl.toLocal8Bit().constData());
	lxDialog->setUrl(QUrl(strFullUrl));


	new LxCoreApplication(this,lxDialog,QString(LOMOX_API_COREAPP));
	LxDialogBase* pDialogOp = new LxDialogBase(lxDialog, lxDialog, "LxDialog");
    this->append(key,pDialogOp);
    return pDialogOp;
}
void MusicSearchEngine::watchForChanges()
{
	// Gather all folders registered on music locations
	QFileInfoList dirs;
	for (QString musicPath : SettingsPrivate::instance()->musicLocations()) {
		QFileInfo location(musicPath);
		QDirIterator it(location.absoluteFilePath(), QDir::Dirs | QDir::Hidden | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
		while (it.hasNext()) {
			QString entry = it.next();
			QFileInfo qFileInfo(entry);
			dirs << qFileInfo;
		}
	}

	SqlDatabase *db = SqlDatabase::instance();
	db->open();
	db->exec("PRAGMA journal_mode = MEMORY");
	db->exec("PRAGMA synchronous = OFF");
	db->exec("PRAGMA temp_store = 2");
	db->exec("PRAGMA foreign_keys = 1");

	QStringList newFoldersToAddInLibrary;
	// Add folders that were not found first
	for (QFileInfo f : dirs) {
		QSqlQuery query = db->exec("SELECT * FROM filesystem WHERE path = \"" + f.absoluteFilePath() + "\"");
		if (!query.next()) {
			newFoldersToAddInLibrary << f.absoluteFilePath();
			QSqlQuery prepared(*db);
			prepared.prepare("INSERT INTO filesystem (path, lastModified) VALUES (?, ?)");
			prepared.addBindValue(f.absoluteFilePath());
			prepared.addBindValue(f.lastModified().toTime_t());
			prepared.exec();
		}
	}

	if (!newFoldersToAddInLibrary.isEmpty()) {
		this->doSearch(newFoldersToAddInLibrary);
	}

	// Process in reverse mode to clean cache: from database file and check if entry exists in database
	QStringList oldLocations;
	QSqlQuery cache = db->exec("SELECT * FROM filesystem");
	while (cache.next()) {
		QDir d(cache.record().value(0).toString());
		d.exists();
		QFileInfo fileInfo(cache.record().value(0).toString());
		// Remove folder in database because it couldn't be find in the filesystem
		if (!fileInfo.exists()) {
			db->exec("DELETE FROM filesystem WHERE path = \"" + fileInfo.absoluteFilePath() + "\"");
			oldLocations << fileInfo.absoluteFilePath();
		}
	}
	if (!oldLocations.isEmpty()) {
		db->rebuild(oldLocations, QStringList());
	}
}
Exemplo n.º 3
0
void    LocalApp::getUrl( QUrl oldUrl , QUrl &newUrl){


    QString scriptName;
#ifndef USE_QT5
#ifdef WINDOWS
    scriptName   = home+"\\" + oldUrl.encodedPath();
#else
    scriptName   = home+"/" + oldUrl.encodedPath();
#endif
    //scriptName   = tmpUrl.toString(FULLPATH);
#else
#ifdef WINDOWS
    scriptName   = home+"\\" + oldUrl.path();
#else
    scriptName   = home+"/" + oldUrl.path();
#endif
    //scriptName   = tmpUrl.toDisplayString(QUrl::FullyDecoded);
    //scriptName.remove(0,6);
#endif
    if( QDir(scriptName).exists() ) {
#ifdef WINDOWS
        if( scriptName.at(scriptName.size()-1) == '/')
#else
        if( scriptName.at(scriptName.size()-1) == '\\')
#endif
            scriptName = scriptName + "index.py";
        else
#ifdef WINDOWS
            scriptName = scriptName + "\\index.py";
#else
            scriptName = scriptName + "/index.py";
#endif
    }
    if ( !getScript(scriptName) ){
        QFileInfo qFileInfo(scriptName);
        if ( qFileInfo.fileName() == "index.py" ){
            scriptName = qFileInfo.dir().absolutePath() + "/index.html";
        }
    }
#ifndef USE_QT5
    ERR<<"INFO: LocalApp::getUrl(): Encoded Path: "<<oldUrl.encodedPath()<<", "<<scriptName<<endl;
    newUrl.setPath(scriptName);
#else
    ERR<<"INFO: LocalApp::getUrl(): Path: "<<oldUrl.path()<<", "<<scriptName<<endl;
    newUrl.setPath(scriptName);
#endif
}
Exemplo n.º 4
0
void LxCoreApplicationPrivate::runLomoxApp(int argc, char *argv[])
{
	QApplication a(argc, argv);

	QWebSettings::globalSettings()->setAttribute(QWebSettings::AutoLoadImages,true);
//#ifdef  DEBUG
	QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled,true);
//#endif

	QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled,true);
	QWebSettings::globalSettings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled,true);
	QWebSettings::globalSettings()->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled,true);
	QWebSettings::globalSettings()->setAttribute(QWebSettings::LocalStorageEnabled,true);
	QWebSettings::globalSettings()->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls,true);
	QWebSettings::globalSettings()->setAttribute(QWebSettings::LocalContentCanAccessFileUrls,true);

	QWebSettings::globalSettings()->setAttribute(QWebSettings::JavascriptCanOpenWindows,true);
	QWebSettings::globalSettings()->setAttribute(QWebSettings::LinksIncludedInFocusChain,true);
	QWebSettings::globalSettings()->setAttribute(QWebSettings::PrintElementBackgrounds, true);
	QWebSettings::globalSettings()->setAttribute(QWebSettings::XSSAuditingEnabled, false);
	QWebSettings::globalSettings()->setAttribute(QWebSettings::NotificationsEnabled, true);
	
	//QWebSettings::globalSettings()->setObjectCacheCapacities(0,0,0); 降低内存用的,但是速度回变低
	QString libraryPath = QCoreApplication::applicationDirPath() + QDir::separator() + QString("plugins\\");
	QStringList libraryPaths;
	libraryPaths.append(libraryPath);
	QCoreApplication::setLibraryPaths(libraryPaths);
	QString strStoragePath = QCoreApplication::applicationDirPath() + QDir::separator() + QString("Storage\\");
	QWebSettings::globalSettings()->enablePersistentStorage(strStoragePath);

	do 
	{
		QString strUrl;
		LxOption* pOtion = getOption();
		if (pOtion)
		{
			strUrl = pOtion->getStartUrl();
		}
		else
			Q_ASSERT(pOtion == nullptr);


		if (!strUrl.isEmpty())
		{
			if (-1 == strUrl.indexOf(':'))
			{
				strUrl = QString::fromLocal8Bit("http://") + strUrl;
			}
			QFileInfo qFileInfo(strUrl);
			if (qFileInfo.isAbsolute())//add by KeoJam 如果是本地文件强制加file:///
			{
				strUrl = QString::fromLocal8Bit("file:///") + strUrl;
			}

			if (!pOtion)
				break;

			QString strTitle = pOtion->getMainTitle();
			if (!strTitle.isEmpty())
				lxCoreApp->setMainDialogTitle(strTitle);
			lxCoreApp->showMainDialog(QUrl(strUrl));
		}
		else
		{
			Q_ASSERT(!strUrl.isEmpty());
			return ;
		}

	} while (false);

	a.exec();
}
Exemplo n.º 5
0
void MusicSearchEngine::doSearch()
{
	qDebug() << Q_FUNC_INFO;
	emit aboutToSearch();

	_db.init();

	QSqlQuery cleanDb(_db);
	cleanDb.setForwardOnly(true);
	//cleanDb.exec("DELETE FROM tracks WHERE uri LIKE 'file:%'");
	//cleanDb.exec("DELETE FROM albums WHERE id NOT IN (SELECT DISTINCT albumId FROM tracks)");
	//cleanDb.exec("DELETE FROM artists WHERE id NOT IN (SELECT DISTINCT artistId FROM tracks)");
	cleanDb.exec("DELETE FROM tracks");
	cleanDb.exec("DELETE FROM albums");
	cleanDb.exec("DELETE FROM artists");
	cleanDb.exec("DROP INDEX indexArtist");
	cleanDb.exec("DROP INDEX indexAlbum");
	cleanDb.exec("DROP INDEX indexPath");
	cleanDb.exec("DROP INDEX indexArtistId");
	cleanDb.exec("DROP INDEX indexAlbumId");
	_db.transaction();

	MusicSearchEngine::isScanning = true;
	QList<QDir> locations;
	QStringList pathsToSearch = _delta.isEmpty() ? SettingsPrivate::instance()->musicLocations() : _delta;
	for (QString musicPath : pathsToSearch) {
		QDir location(musicPath);
		location.setFilter(QDir::AllDirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot);
		locations.append(location);
	}

	int entryCount = 0;
	// QDirIterator class is very fast to scan large directories
	for (QDir location : locations) {
		QDirIterator it(location.absolutePath(), QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
		while (it.hasNext()) {
			it.next();
			entryCount++;
		}
	}

	int currentEntry = 0;
	int percent = 1;
	bool atLeastOneAudioFileWasFound = false;
	bool isNewDirectory = false;

	QString coverPath;
	QString lastFileScannedNextToCover;

	QStringList suffixes = FileHelper::suffixes(FileHelper::All);

	for (QDir location : locations) {
		QDirIterator it(location.absolutePath(), QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
		while (it.hasNext()) {
			QString entry = it.next();
			QFileInfo qFileInfo(entry);
			currentEntry++;

			// Directory has changed: we can discard cover
			if (qFileInfo.isDir()) {
				if (!coverPath.isEmpty() && !lastFileScannedNextToCover.isEmpty()) {
					_db.saveCoverRef(coverPath, lastFileScannedNextToCover);
					coverPath.clear();
				}
				isNewDirectory = true;
				atLeastOneAudioFileWasFound = false;
				lastFileScannedNextToCover.clear();
				continue;
			} else if (qFileInfo.suffix().toLower() == "jpg" || qFileInfo.suffix().toLower() == "png") {
				if (atLeastOneAudioFileWasFound) {
					coverPath = qFileInfo.absoluteFilePath();
					_db.saveCoverRef(coverPath, lastFileScannedNextToCover);
					coverPath.clear();
				} else if (isNewDirectory) {
					coverPath = qFileInfo.absoluteFilePath();
				}
			} else if (suffixes.contains(qFileInfo.suffix())) {
				_db.saveFileRef(qFileInfo.absoluteFilePath());
				atLeastOneAudioFileWasFound = true;
				lastFileScannedNextToCover = qFileInfo.absoluteFilePath();
				isNewDirectory = false;
			}

			if (currentEntry * 100 / entryCount > percent) {
				percent = currentEntry * 100 / entryCount;
				emit progressChanged(percent);
				qApp->processEvents();
			}
		}
		atLeastOneAudioFileWasFound = false;
	}

	_db.commit();

	QSqlQuery index(_db);
	index.exec("CREATE INDEX IF NOT EXISTS indexArtist ON tracks (artistId)");
	index.exec("CREATE INDEX IF NOT EXISTS indexAlbum ON tracks (albumId)");
	index.exec("CREATE INDEX IF NOT EXISTS indexPath ON tracks (uri)");
	index.exec("CREATE INDEX IF NOT EXISTS indexArtistId ON artists (id)");
	index.exec("CREATE INDEX IF NOT EXISTS indexAlbumId ON albums (id)");

	// Resync remote players and remote databases
	//emit aboutToResyncRemoteSources();

	MusicSearchEngine::isScanning = false;
	emit searchHasEnded();

	this->deleteLater();
}
Exemplo n.º 6
0
void ClsQHarborImpl::slotSaveParamSet() {
#ifdef DEBUG_CLSQHARBORIMPL
    cout << "ClsQHarborImpl::slotSaveParamSet()" << endl;
#endif


    QString qstrFileName = "";
    bool bValidFile = false;
    while(!bValidFile) {
        qstrFileName = QFileDialog::getSaveFileName(
                           /*QDir::homeDirPath ()*/ "",
                           "Harbor ParamSet (*.pconf)",
                           this,
                           "Save File"
                           "Choose a filename to save under" );

        /* append default extension here */
        QString qstrExtension( ".pconf" );
        QString qstrCurrentTail = qstrFileName.right(qstrExtension.length());
        if(qstrCurrentTail.compare(qstrExtension)) {
            qstrFileName.append(qstrExtension);
        }
        /* ------------------------------ */


        QFileInfo qFileInfo(qstrFileName );
        QString qstrPath = qFileInfo.dirPath(true);
        qFileInfo.setFile (qstrPath);
        if ( !qFileInfo.isWritable() ) {
            int iReturn = QMessageBox::critical( this, "iqr",
                                                 "No permission to write in this directory\n",
                                                 "Retry", "Cancel", 0, 0, 1 );
            if(iReturn == 1) {
                return;
            }
        } else {
            bValidFile = true;
        }
    }

    if(qstrFileName.length()<=0) {
        return;
    }


    if ( QFile::exists(qstrFileName) ) {
        /*      warning on overwrite */
        int iReturn = QMessageBox::warning( this, "iqr",
                                            "A file with the seleteced name exists\n",
                                            "Overwrite", "Cancel", 0, 0, 1 );
        if(iReturn == 1) {
            return;
        }
    }


    QDomDocument doc( "ParamSet" );
    QDomElement root = doc.createElement( "ParamSet" );
    doc.appendChild( root );


    for(int ii = 0; ii<qtableEntries->numRows(); ii++) {
        QDomElement parameter = doc.createElement( "Parameter" );
        parameter.setAttribute ( "itemType", qtableEntries->text(ii, COL_TYPE) );
        parameter.setAttribute ( "itemID", qtableEntries->text(ii, COL_ID) );
        parameter.setAttribute ( "name", qtableEntries->text(ii, COL_PARAM_NAME) );
        parameter.setAttribute ( "value", qtableEntries->text(ii, COL_VALUE) );

        root.appendChild( parameter );

    }
    QString xml = doc.toString();
//    cout << xml << endl;


    QFile file(qstrFileName);
    if ( file.open( IO_WriteOnly ) ) {
        QTextStream stream( &file );
        stream << doc.toString() << "\n";
        file.close();
    }


}
void MusicSearchEngine::doSearch(const QStringList &delta)
{
	//qDebug() << Q_FUNC_INFO << delta;
	MusicSearchEngine::isScanning = true;
	QList<QDir> locations;
	QStringList pathsToSearch = delta.isEmpty() ? SettingsPrivate::instance()->musicLocations() : delta;
	for (QString musicPath : pathsToSearch) {
		QDir location(musicPath);
		location.setFilter(QDir::AllDirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot);
		locations.append(location);
	}

	int entryCount = 0;
	// QDirIterator class is very fast to scan large directories
	for (QDir location : locations) {
		QDirIterator it(location.absolutePath(), QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
		while (it.hasNext()) {
			it.next();
			entryCount++;
		}
	}

	int currentEntry = 0;
	int percent = 1;
	bool atLeastOneAudioFileWasFound = false;
	bool isNewDirectory = false;

	QString coverPath;
	QString lastFileScannedNextToCover;

	QStringList suffixes = FileHelper::suffixes(FileHelper::All);

	for (QDir location : locations) {
		QDirIterator it(location.absolutePath(), QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
		while (it.hasNext()) {
			QString entry = it.next();
			QFileInfo qFileInfo(entry);
			currentEntry++;

			// Directory has changed: we can discard cover
			if (qFileInfo.isDir()) {
				if (!coverPath.isEmpty() && !lastFileScannedNextToCover.isEmpty()) {
					emit scannedCover(coverPath, lastFileScannedNextToCover);
					coverPath.clear();
				}
				isNewDirectory = true;
				atLeastOneAudioFileWasFound = false;
				lastFileScannedNextToCover.clear();
				continue;
			} else if (qFileInfo.suffix().toLower() == "jpg" || qFileInfo.suffix().toLower() == "png") {
				if (atLeastOneAudioFileWasFound) {
					coverPath = qFileInfo.absoluteFilePath();
					emit scannedCover(coverPath, lastFileScannedNextToCover);
					coverPath.clear();
				} else if (isNewDirectory) {
					coverPath = qFileInfo.absoluteFilePath();
				}
			} else if (suffixes.contains(qFileInfo.suffix())) {
				emit scannedFile(qFileInfo.absoluteFilePath());
				atLeastOneAudioFileWasFound = true;
				lastFileScannedNextToCover = qFileInfo.absoluteFilePath();
				isNewDirectory = false;
			}

			if (currentEntry * 100 / entryCount > percent) {
				percent = currentEntry * 100 / entryCount;
				emit progressChanged(percent);
			}
		}
		atLeastOneAudioFileWasFound = false;
	}
	emit searchHasEnded();
	MusicSearchEngine::isScanning = false;
}
Exemplo n.º 8
0
void ClsQHarborImpl::slotSaveParamSet(){
#ifdef DEBUG_CLSQHARBORIMPL
    cout << "ClsQHarborImpl::slotSaveParamSet()" << endl;
#endif


    QString qstrFileName = "";
    bool bValidFile = false;
    while(!bValidFile){
	qstrFileName = QFileDialog::getSaveFileName(
	    this, 
	    "Save File"
	    "Choose a filename to save under",
	    "",
 	    "Harbor ParamSet (*.pconf)" );

	QFileInfo qFileInfo(qstrFileName );
	QString qstrPath = qFileInfo.dirPath(true);
	qFileInfo.setFile (qstrPath);
	if ( !qFileInfo.isWritable() ) {
	    int iReturn = QMessageBox::critical( this, "iqr",
						 "No permission to write in this directory\n",
						 "Retry", "Cancel", 0, 0, 1 );
	    if(iReturn == 1){
		return;
	    }
	} else {
	    bValidFile = true;
	}
    }
    
    if(qstrFileName.length()<=0){
	return;
    }


    if ( QFile::exists(qstrFileName) ) {
/*      warning on overwrite */
	int iReturn = QMessageBox::warning( this, "iqr",
					    "A file with the seleteced name exists\n",
					    "Overwrite", "Cancel", 0, 0, 1 );
	if(iReturn == 1){
	    return;
	}
    }


    QDomDocument doc( "ParamSet" );
    QDomElement root = doc.createElement( "ParamSet" );
    doc.appendChild( root );

    
    for(int ii = 0; ii<tableWidget->rowCount(); ii++){
	QDomElement parameter = doc.createElement( "Parameter" );
	parameter.setAttribute ( "itemType", getItemValue(ii, COL_TYPE).c_str() );
	parameter.setAttribute ( "itemID", getItemValue(ii, COL_ID).c_str() );
	parameter.setAttribute ( "name", getItemValue(ii, COL_PARAM_NAME).c_str() );
	parameter.setAttribute ( "value", getItemValue(ii, COL_VALUE).c_str() );
	
	root.appendChild( parameter );

    }	    
    QString xml = doc.toString();
//    cout << xml << endl;


    QFile file(qstrFileName);
    if ( file.open( QIODevice::WriteOnly ) ) {
        QTextStream stream( &file );
	stream << doc.toString() << "\n";
        file.close();
    }


}
Exemplo n.º 9
0
void MainWindow::startPatching()
{
    Q_D(MainWindow);

    d->bytes = 0;
    d->maxBytes = 0;
    d->files = 0;
    d->maxFiles = 0;

    d->progressBar->setMaximum(0);
    d->progressBar->setValue(0);
    d->detailsLbl->clear();

    d->state = MainWindowPrivate::Patching;
    updateWidgetsVisibility();

    QString romId;
    if (d->instLocSel->currentIndex() == d->instLocs.size()) {
        romId = QStringLiteral("data-slot-%1").arg(d->instLocLe->text());
    } else if (d->instLocSel->currentIndex() == d->instLocs.size() + 1) {
        romId = QStringLiteral("extsd-slot-%1").arg(d->instLocLe->text());
    } else {
        romId = d->instLocs[d->instLocSel->currentIndex()].id;
    }


    QStringList suffixes;
    suffixes << QStringLiteral(".tar.md5");
    suffixes << QStringLiteral(".tar.md5.gz");
    suffixes << QStringLiteral(".tar.md5.xz");
    suffixes << QStringLiteral(".zip");

    QFileInfo qFileInfo(d->fileName);
    QString suffix;
    QString outputName;
    bool isOdin = false;

    for (const QString &suffix : suffixes) {
        if (d->fileName.endsWith(suffix)) {
            // Input name: <parent path>/<base name>.<suffix>
            // Output name: <parent path>/<base name>_<rom id>.zip
            outputName = d->fileName.left(d->fileName.size() - suffix.size())
                    % QStringLiteral("_")
                    % romId
                    % QStringLiteral(".zip");
            isOdin = suffix.contains(QStringLiteral(".tar.md5"));
            break;
        }
    }
    if (outputName.isEmpty()) {
        outputName = qFileInfo.completeBaseName()
                % QStringLiteral("_")
                % romId
                % QStringLiteral(".")
                % qFileInfo.suffix();
    }

    QString inputPath(QDir::toNativeSeparators(qFileInfo.filePath()));
    QString outputPath(QDir::toNativeSeparators(
            qFileInfo.dir().filePath(outputName)));

    FileInfoPtr fileInfo = new mbp::FileInfo();
    fileInfo->setInputPath(inputPath.toUtf8().constData());
    fileInfo->setOutputPath(outputPath.toUtf8().constData());
    fileInfo->setDevice(d->device);
    fileInfo->setRomId(romId.toUtf8().constData());

    if (isOdin) {
        d->patcher = d->pc->createPatcher("OdinPatcher");
    } else {
        d->patcher = d->pc->createPatcher("MultiBootPatcher");
    }

    emit runThread(d->patcher, fileInfo);
}