Esempio n. 1
0
frmNapiProjektUpload::frmNapiProjektUpload(QWidget * parent, Qt::WindowFlags f) : QDialog(parent, f)
{
    ui.setupUi(this);

    setAttribute(Qt::WA_QuitOnClose, false);

    connect(ui.pbSelectDirectory, SIGNAL(clicked()), this, SLOT(selectDirectory()));
    connect(ui.leSelectDirectory, SIGNAL(textChanged(QString)), this, SLOT(leSelectDirectoryChanged()));
    connect(ui.pbScan, SIGNAL(clicked()), this, SLOT(pbScanClicked()));
    connect(&scanThread, SIGNAL(scanFinished(bool)), this, SLOT(scanFinished(bool)));
    connect(&scanThread, SIGNAL(folderChange(QString)), this, SLOT(folderChange(QString)));
    connect(ui.pbUpload, SIGNAL(clicked()), this, SLOT(pbUploadClicked()));
    connect(&uploadThread, SIGNAL(finished()), this, SLOT(uploadFinished()));
    connect(&uploadThread, SIGNAL(progressChange(int)), ui.pbProgress, SLOT(setValue(int)));
    connect(&uploadThread, SIGNAL(fileNameChange(QString)), this, SLOT(fileNameChange(QString)));
    connect(&uploadThread, SIGNAL(checkingUserPass()), this, SLOT(checkingUserPass()));
    connect(&uploadThread, SIGNAL(invalidUserPass()), this, SLOT(invalidUserPass()));

    if(QFileInfo(GlobalConfig().previousDialogPath()).isDir())
        ui.leSelectDirectory->setText(GlobalConfig().previousDialogPath());

    QRect position = frameGeometry();
    position.moveCenter(QDesktopWidget().availableGeometry().center());
    move(position.topLeft());
}
Esempio n. 2
0
void PostThread::run()
{
    abort = false;

    if(!QNapiProjektEngine::checkUser(  GlobalConfig().nick("NapiProjekt"),
                                        GlobalConfig().pass("NapiProjekt")))
    {
        emit invalidUserPass();
        emit postFinished(true);
        return;
    }

    if(abort)
    {
        postFinished(true);
        return;
    }

    QNapiProjektEngine *napi;

    if((napi = new QNapiProjektEngine(movie, subtitles)))
    {
        taskResult = napi->uploadSubtitles( language,
                                            GlobalConfig().nick("NapiProjekt"),
                                            GlobalConfig().pass("NapiProjekt"),
                                            true,
                                            comment);
        delete napi;
    }

    postFinished();
}
Esempio n. 3
0
frmUpload::frmUpload(QWidget * parent, Qt::WindowFlags f) : QDialog(parent, f)
{
    ui.setupUi(this);

    setAttribute(Qt::WA_QuitOnClose, false);

    connect(ui.pbSelectDirectory, SIGNAL(clicked()), this, SLOT(selectDirectory()));
    connect(ui.leSelectDirectory, SIGNAL(textChanged(QString)), this, SLOT(leSelectDirectoryChanged()));
    connect(ui.pbScan, SIGNAL(clicked()), this, SLOT(pbScanClicked()));
    connect(&scanThread, SIGNAL(scanFinished(bool)), this, SLOT(scanFinished(bool)));
    connect(&scanThread, SIGNAL(folderChange(QString)), this, SLOT(folderChange(QString)));
    connect(ui.pbUpload, SIGNAL(clicked()), this, SLOT(pbUploadClicked()));
    connect(&uploadThread, SIGNAL(finished()), this, SLOT(uploadFinished()));
    connect(&uploadThread, SIGNAL(progressChange(int)), ui.pbProgress, SLOT(setValue(int)));
    connect(&uploadThread, SIGNAL(fileNameChange(QString)), this, SLOT(fileNameChange(QString)));
    connect(&uploadThread, SIGNAL(checkingUserPass()), this, SLOT(checkingUserPass()));
    connect(&uploadThread, SIGNAL(invalidUserPass()), this, SLOT(invalidUserPass()));

    if(QFileInfo(GlobalConfig().previousDialogPath()).isDir())
        ui.leSelectDirectory->setText(GlobalConfig().previousDialogPath());

    // workaround dla compiza?
    move((QApplication::desktop()->width() - width()) / 2, 
        (QApplication::desktop()->height() - height()) / 2);
}
Esempio n. 4
0
void frmCreateUser::serverMessage(QString msg)
{
	QRegExp extract("<A HREF=\"index.php3\\?msg=(.*)\">", Qt::CaseInsensitive);
	if(extract.indexIn(msg) > -1)
		msg = extract.cap(1).replace("%20", " ");

	if((msg.indexOf("NPc0") == 0) || (msg.indexOf("Konto zostalo zalozone!") == 0))
	{
		msg = tr("Konto na serwerze NAPI zostało założone!");
		QMessageBox::information(this, tr("Konto założone"), msg);

		if( QMessageBox::question(this, tr("QNapi"), tr("Czy chcesz uaktualnić ustawienia w programie?"),
			QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes )
		{
			GlobalConfig().setNick("NapiProjekt", ui.leLogin->text());
			GlobalConfig().setPass("NapiProjekt", ui.lePass->text());
			GlobalConfig().save();
		}

		if(createUserThread.isRunning())
			createUserThread.wait();
		close();
	}
	else
	{
		msg = tr("Odpowiedź serwera: ") + tr(qPrintable(msg));
		QMessageBox::information(this, tr("Operacja zakończona"), msg);
	}
}
Esempio n. 5
0
// konstruktor klasy
QNapiProjektEngine::QNapiProjektEngine(const QString & movieFile, const QString & subtitlesFile)
    : QNapiAbstractEngine(movieFile, subtitlesFile)
{
    p7zipPath = GlobalConfig().p7zipPath();
    nick = GlobalConfig().nick(engineName());
    pass = GlobalConfig().pass(engineName());
    noBackup = GlobalConfig().noBackup();
    tmpPackedFile =  QString("%1/%2").arg(tmpPath).arg(generateTmpFileName());
}
// Dokonuje post-przetwarzania pliku z napisami (na podstawie konfiguracji)
void QNapiAbstractEngine::pp()
{
    // Usuwanie linii z plikow z napisami
    if(GlobalConfig().ppRemoveLines())
    {
        ppRemoveLinesContainingWords(GlobalConfig().ppRemoveWords());
    }

    // Zmiana kodowania pobranych napisow
    switch (GlobalConfig().ppEncodingMethod()) {
        case CEM_REPLACE_DIACRITICS:
            ppReplaceDiacriticsWithASCII();
        break;
        case CEM_CHANGE:
            // Jesli automatycznie nie uda mu sie wykryc kodowania, to jako kodowania
            // zrodlowego uzywa kodowania wybranego przez uzytkownika
            if (!GlobalConfig().ppAutoDetectEncoding()
                || !ppChangeSubtitlesEncoding(GlobalConfig().ppEncodingTo()))
            {
                ppChangeSubtitlesEncoding(GlobalConfig().ppEncodingFrom(),
                                            GlobalConfig().ppEncodingTo());
            }
        break;
        case CEM_ORIGINAL:
            // Nie ruszaj pobranych napisów!
        break;
    }

    if(!GlobalConfig().ppSubFormat().isEmpty())
    {
        SubtitleConverter sc;
        QString targetFormat = GlobalConfig().ppSubFormat();
        sc.convertSubtitles(subtitlesTmp, targetFormat, subtitlesTmp, movie);
    }
}
Esempio n. 7
0
void frmCorrect::selectSubtitles()
{
    QString fileName;
    QNapiOpenDialog openDialog(this, tr("Wskaż plik z napisami"),
                                GlobalConfig().previousDialogPath(), QNapiOpenDialog::Subtitles);

    if(openDialog.selectFile())
    {
        fileName = openDialog.selectedFiles().first();
        GlobalConfig().setPreviousDialogPath(openDialog.directory().path());
    }

    if(!fileName.isEmpty() && QFile::exists(fileName))
        ui.leSubtitlesSelect->setText(fileName);
}
Esempio n. 8
0
frmAbout::frmAbout(QWidget * parent, Qt::WFlags f) : QDialog(parent, f)
{
	ui.setupUi(this);

#ifdef Q_WS_MAC
	setAttribute(Qt::WA_MacBrushedMetal, GlobalConfig().useBrushedMetal());
#endif

	setAttribute(Qt::WA_QuitOnClose, false);
	ui.lbTitle->setText(QString("QNapi ") + QNAPI_DISPLAYABLE_VERSION);

const QString www = tr("<a href=\"http://krzemin.iglu.cz/qnapi\">http://krzemin.iglu.cz/qnapi</a>");
const QString author = tr("Copyright (C) 2008-2009 Krzemin &lt;<a href=\"mailto:[email protected]\">[email protected]</a>&gt;");
const QString useos = tr("Program korzysta z bazy <a href=\"http://www.opensubtitles.org\">http://www.opensubtitles.org</a>");
const QString usenp = tr("Program korzysta z bazy <a href=\"http://www.napiprojekt.pl\">http://www.napiprojekt.pl</a>");

	ui.lbWWW->setText(www);
	ui.lbAuthor->setText(author);
	ui.lbUseOS->setText(useos);
	ui.lbUseNP->setText(usenp);

	// workaround dla compiza?
	move((QApplication::desktop()->width() - width()) / 2, 
		(QApplication::desktop()->height() - height()) / 2);
}
Esempio n. 9
0
frmProgress::frmProgress(QWidget * parent, Qt::WFlags f) : QWidget(parent, f)
{
	qRegisterMetaType<QNapiSubtitleInfoList>("QNapiSubtitleInfoList");

	ui.setupUi(this);

#ifdef Q_WS_MAC
	setAttribute(Qt::WA_MacBrushedMetal, GlobalConfig().useBrushedMetal());
#endif
	setAttribute(Qt::WA_DeleteOnClose, false);
	setAttribute(Qt::WA_QuitOnClose, false);

	setBatchMode(false);

	connect(&getThread, SIGNAL(fileNameChange(const QString &)),
			ui.lbFileName, SLOT(setText(const QString &)));
	connect(&getThread, SIGNAL(actionChange(const QString &)),
			ui.lbAction, SLOT(setText(const QString &)));
	connect(&getThread, SIGNAL(progressChange(int, int, float)),
			this, SLOT(updateProgress(int, int, float)));
	connect(&getThread, SIGNAL(selectSubtitles(QString, QNapiSubtitleInfoList)),
			this, SLOT(selectSubtitles(QString, QNapiSubtitleInfoList)));
	connect(this, SIGNAL(subtitlesSelected(int)),
			&getThread, SLOT(subtitlesSelected(int)));
	connect(&getThread, SIGNAL(finished()),
			this, SLOT(downloadFinished()));
}
Esempio n. 10
0
void UploadThread::run()
{
    added_new = added_ok = failed = 0;
    abort = false;
    invalidUP = false;

    emit checkingUserPass();

    if(!QNapiProjektEngine::checkUser(  GlobalConfig().nick("NapiProjekt"),
                                        GlobalConfig().pass("NapiProjekt")))
    {
        invalidUP = true;
        emit invalidUserPass();
        return;
    }

    if(abort) return;

    int size = movieList.size();
    QNapiProjektEngine *napi;

    for(int i = 0; i < size; i++)
    {
        QFileInfo fi(movieList[i]);
        napi = new QNapiProjektEngine(movieList[i], fi.path() + "/" + fi.completeBaseName() + ".txt");
        if(!napi) continue;

        emit fileNameChange(fi.fileName());
        emit progressChange(i * 100 / size);
        
        switch( napi->uploadSubtitles(  GlobalConfig().language(),
                                        GlobalConfig().nick("NapiProjekt"),
                                        GlobalConfig().pass("NapiProjekt"),
                                        false ) )
        {
            case QNapiProjektEngine::NAPI_ADDED_NEW: ++added_new; break;
            case QNapiProjektEngine::NAPI_FAIL: ++failed; break;
            default: ++added_ok; break;
        }

        delete napi;
        if(abort) break;
    }
    
    emit progressChange(100);
}
Esempio n. 11
0
QNapiOpenDialog::QNapiOpenDialog( QWidget * parent, const QString & caption,
									const QString & init_path,
									FilterMode filterMode )
							: QFileDialog(parent)
{
	setAttribute(Qt::WA_QuitOnClose, false);
	setWindowTitle(caption);

	if(filterMode == Movies)
	{
#if QT_VERSION >= 0x040400
		setNameFilter
#else
		setFilter
#endif
				(tr("Filmy (*.avi *.asf *.divx *.mkv *.mov *.mp4 *.mpeg *.mpg *.ogm "
					"*.rm *.rmvb *.wmv);;Wszystkie pliki (*.*)"));
	}
	else if(filterMode == Subtitles)
	{
#if QT_VERSION >= 0x040400
		setNameFilter
#else
		setFilter
#endif
				(tr("Napisy (*.txt);;Wszystkie pliki (*.*)"));
	}

	if(QFileInfo(init_path).isDir())
		setDirectory(init_path);
	else
		setDirectory(QDir::currentPath());

	QStringList sideUrls;
	
#ifdef Q_WS_MAC
	sideUrls << "/Volumes";
	setAttribute(Qt::WA_MacBrushedMetal, GlobalConfig().useBrushedMetal());
#endif

	sideUrls << QString(QDir::homePath() + "/Movies") << QString(QDir::homePath() + "/movies")
				<< QString(QDir::homePath() + "/Video") << QString(QDir::homePath() + "/video")
				<< QString(QDir::homePath() + "/Filmy") << QString(QDir::homePath() + "/filmy")
				<< QString(QDir::homePath() + "/Wideo") << QString(QDir::homePath() + "/wideo");

	QList<QUrl> urls = sidebarUrls();

	foreach(QString sideUrl, sideUrls)
	{
		if(!QDir().exists(sideUrl)) continue;
		QUrl url = QUrl::fromLocalFile(sideUrl);
		if(!urls.contains(url))
			urls << url;
	}

	setSidebarUrls(urls);
}
Esempio n. 12
0
QList<VideoCaptureDevice> BackendCapabilities::availableVideoCaptureDevices()
{
    QList<VideoCaptureDevice> ret;
    const QList<int> deviceIndexes = GlobalConfig().videoCaptureDeviceListFor(Phonon::NoCaptureCategory, GlobalConfig::ShowAdvancedDevices);
    for (int i = 0; i < deviceIndexes.count(); ++i) {
        ret.append(VideoCaptureDevice::fromIndex(deviceIndexes.at(i)));
    }
    return ret;
}
Esempio n. 13
0
QList<AudioCaptureDevice> BackendCapabilities::availableAudioCaptureDevices()
{
    QList<AudioCaptureDevice> ret;
    const QList<int> deviceIndexes = GlobalConfig().audioCaptureDeviceListFor(Phonon::NoCategory);
    for (int i = 0; i < deviceIndexes.count(); ++i) {
        ret.append(AudioCaptureDevice::fromIndex(deviceIndexes.at(i)));
    }
    return ret;
}
Esempio n. 14
0
QList<AudioOutputDevice> BackendCapabilities::availableAudioOutputDevices()
{
    QList<AudioOutputDevice> ret;
#ifndef QT_NO_PHONON_SETTINGSGROUP
    const QList<int> deviceIndexes = GlobalConfig().audioOutputDeviceListFor(Phonon::NoCategory);
    for (int i = 0; i < deviceIndexes.count(); ++i) {
        ret.append(AudioOutputDevice::fromIndex(deviceIndexes.at(i)));
    }
#endif //QT_NO_PHONON_SETTINGSGROUP
    return ret;
}
Esempio n. 15
0
	void EditorConfig::LoadGlobalConfig()
	{
		DataNode data;
		if (data.LoadFromFile(mGlobalConfigPath))
			mGlobalConfig = data;
		else
		{
			mGlobalConfig = GlobalConfig();
			mGlobalConfig.mLastOpenedProjectpath = GetProjectPath();
		}
	}
Esempio n. 16
0
QList<VideoCaptureDevice> BackendCapabilities::availableAVCaptureDevices()
{
    QList<VideoCaptureDevice> ret;
    const QList<int> deviceIndexes = GlobalConfig().videoCaptureDeviceListFor(Phonon::NoCaptureCategory, GlobalConfig::ShowAdvancedDevices);
    for (int i = 0; i < deviceIndexes.count(); ++i) {
        VideoCaptureDevice vcd = VideoCaptureDevice::fromIndex(deviceIndexes.at(i));
        if (vcd.propertyNames().contains("hasaudio") && vcd.property("hasaudio").isValid())
            ret.append(vcd);
    }
    return ret;
}
Esempio n. 17
0
void frmCorrect::selectMovie()
{
    QString fileName;
    QNapiOpenDialog openDialog(this, tr("Wskaż plik z filmem"),
                                GlobalConfig().previousDialogPath(), QNapiOpenDialog::Movies);

    if(openDialog.selectFile())
    {
        fileName = openDialog.selectedFiles().first();
        GlobalConfig().setPreviousDialogPath(openDialog.directory().path());
    }

    if(!fileName.isEmpty() && QFile::exists(fileName))
        ui.leMovieSelect->setText(fileName);

    QFileInfo fi(fileName);
    QString propSubtitleFile = fi.path() + "/" + fi.completeBaseName() + ".txt";

    if(QFile::exists(propSubtitleFile))
        ui.leSubtitlesSelect->setText(propSubtitleFile);
}
Esempio n. 18
0
frmSummary::frmSummary(QWidget * parent, Qt::WFlags f) : QDialog(parent, f)
{
	ui.setupUi(this);

#ifdef Q_WS_MAC
	setAttribute(Qt::WA_MacBrushedMetal, GlobalConfig().useBrushedMetal());
#endif
	setAttribute(Qt::WA_QuitOnClose, false);

	// workaround dla compiza?
	move((QApplication::desktop()->width() - width()) / 2, 
		(QApplication::desktop()->height() - height()) / 2);
}
Esempio n. 19
0
void frmNapiProjektUpload::selectDirectory()
{
    QString dir = QFileInfo(ui.leSelectDirectory->text()).path();
    dir = QDir().exists(dir) ? dir : GlobalConfig().previousDialogPath();

    QNapiOpenDialog openDialog(this, tr("Wskaż katalog do skanowania"),
                                dir, QNapiOpenDialog::None);

    if(openDialog.selectDirectory())
        dir = openDialog.selectedFiles().first();

    if(!dir.isEmpty() && QDir().exists(dir))
        ui.leSelectDirectory->setText(dir);
}
Esempio n. 20
0
bool QNapi::checkAll()
{
    if(!QFileInfo(GlobalConfig().p7zipPath()).isExecutable())
    {
        QMessageBox::warning(0, tr("Brak programu p7zip!"),
                                tr("Ścieżka do programu p7zip jest nieprawidłowa!"));
        return false;
    }

    QFileInfo f(GlobalConfig().tmpPath());

    if(!(f.isDir() && f.isWritable()))
    {
        QMessageBox::warning(0, tr("Nieprawidłowy katalog tymczasowy!"),
                                tr("Nie można pisać do katalogu tymczasowego! Sprawdź swoje ustawienia."));
        return false;
    }

    bool flag = true;

    foreach(QString movie, m_movies)
    {
        flag = flag && QFileInfo(QFileInfo(movie).absolutePath()).isWritable();
    }
// Usuwanie linii zawierajacych podane slowa z pliku z napisami
bool QNapiAbstractEngine::ppRemoveLinesContainingWords(QStringList wordList)
{
    if(!QFileInfo(subtitlesTmp).exists())
        return false;

    wordList = wordList.filter(QRegExp("^(.+)$"));

    QString fromCodec = ppDetectEncoding(subtitlesTmp);

    if(fromCodec.isEmpty())
        fromCodec = GlobalConfig().ppEncodingFrom();

    QFile f(subtitlesTmp);
    if(!f.open(QIODevice::ReadOnly | QIODevice::Text))
        return false;

    QList<QByteArray> lines = f.readAll().split('\n');
    QList<QByteArray> out;

    foreach(QByteArray line, lines)
    {
        int i;
        while((i = line.indexOf('\r')) >= 0)
            line.remove(i, 1);

        QTextStream ts(line);
        ts.setCodec(qPrintable(fromCodec));
        QString encLine = ts.readAll();

        if(encLine.isEmpty())
        {
            out << line;
            continue;
        }

        bool found = false;
        foreach(QString word, wordList)
        {
            if(encLine.contains(word, Qt::CaseInsensitive))
            {
                found = true;
                break;
            }
        }
        if(found) continue;

        out << line;
    }
Esempio n. 22
0
// Dokonuje post-przetwarzania pliku z napisami (na podstawie konfiguracji)
void QNapiAbstractEngine::pp()
{
	// Usuwanie linii z plikow z napisami
	if(GlobalConfig().ppRemoveLines())
	{
		ppRemoveLinesContainingWords(GlobalConfig().ppRemoveWords());
	}

	// Zmiana kodowania pobranych napisow
	if(GlobalConfig().ppChangeEncoding())
	{
		// Jesli automatycznie nie uda mu sie wykryc kodowania, to jako kodowania
		// zrodlowego uzywa kodowania wybranego przez uzytkownika
		if (!GlobalConfig().ppAutoDetectEncoding()
			|| !ppChangeSubtitlesEncoding(GlobalConfig().ppEncodingTo()))
		{
			ppChangeSubtitlesEncoding(GlobalConfig().ppEncodingFrom(),
										GlobalConfig().ppEncodingTo());
		}
	}

#ifndef Q_WS_WIN
	// Zmiana uprawnien do pliku
	if(GlobalConfig().ppChangePermissions())
	{
		bool validPermissions;
		int permInt = GlobalConfig().ppPermissions().toInt(&validPermissions, 8);

		if(validPermissions)
		{
			int perm = 0;
			perm |= (permInt & 0700) << 2;
			perm |= (permInt & 0070) << 1;
			perm |= (permInt & 0007);
			ppChangeSubtitlesPermissions(QFile::Permissions(perm));
		}
	}
#endif
}
Esempio n. 23
0
void sigHandler(int sig)
{
	Q_UNUSED(sig);

	qDebug() << "\nQNapi: usuwanie plików tymczasowych...";

	QString tmpPath = GlobalConfig().tmpPath();

	QStringList filters;
	filters << "QNapi-*-rc";
	filters << "QNapi.*.tmp";

	QDir dir(tmpPath);

	QStringList files = dir.entryList(filters);

	foreach(QString file, files)
	{
		QFile::remove(tmpPath + QDir::separator() + file);
	}
Esempio n. 24
0
frmCreateUser::frmCreateUser(QWidget * parent, Qt::WFlags f) : QDialog(parent, f)
{
	ui.setupUi(this);

#ifdef Q_WS_MAC
	setAttribute(Qt::WA_MacBrushedMetal, GlobalConfig().useBrushedMetal());
#endif
	setAttribute(Qt::WA_QuitOnClose, false);

	connect(ui.pbCreate, SIGNAL(clicked()), this, SLOT(pbCreateClicked()));

	connect(ui.leLogin, SIGNAL(textChanged(QString)), this, SLOT(checkCreateEnable()));
	connect(ui.lePass, SIGNAL(textChanged(QString)), this, SLOT(checkCreateEnable()));
	connect(ui.leRepeatPass, SIGNAL(textChanged(QString)), this, SLOT(checkCreateEnable()));
	connect(ui.leMail, SIGNAL(textChanged(QString)), this, SLOT(checkCreateEnable()));
	connect(&createUserThread, SIGNAL(creatingFinished(bool)), this, SLOT(creatingFinished(bool)));
	connect(&createUserThread, SIGNAL(serverMessage(QString)), this, SLOT(serverMessage(QString)));
	connect(&createUserThread, SIGNAL(terminated()), this, SLOT(creatingFinished()));

	// workaround dla compiza?
	move((QApplication::desktop()->width() - width()) / 2, 
		(QApplication::desktop()->height() - height()) / 2);
}
// dopasowuje napisy do pliku z filmem
bool QNapiAbstractEngine::match()
{
    QFileInfo stf(subtitlesTmp);

    if(!stf.exists())
        return false;

    QString targetExtension = stf.suffix();

    if(!GlobalConfig().ppSubFormat().isEmpty() && GlobalConfig().ppSubExtension().isEmpty())
    {
        targetExtension = GlobalFormatsRegistry().select(GlobalConfig().ppSubFormat())->defaultExtension();
    }
    else if(!GlobalConfig().ppSubExtension().isEmpty())
    {
        targetExtension = GlobalConfig().ppSubExtension();
    }

    QFileInfo mf(movie);

    subtitles = mf.path() + "/" + mf.completeBaseName() + "." + targetExtension;

    QFileInfo sf(subtitles);

    if(!QFileInfo(sf.absolutePath()).isWritable())
        return false;

    if(QFile::exists(subtitles))
    {
        if(!noBackup)
        {
            QString newName = mf.path() + QDir::separator() + mf.completeBaseName() + "_kopia." + sf.suffix();

            if(QFile::exists(newName))
                QFile::remove(newName);

            QFile::rename(subtitles, newName);          
        }
        else
            QFile::remove(subtitles);
    }

    bool r = false;

#ifdef Q_OS_WIN
    // Pod windowsem, aby "wyczyscic" atrybuty pliku, tworzymy go na nowo
    QFile f(subtitles), f2(subtitlesTmp);
    if(!f.open(QIODevice::WriteOnly) || !f2.open(QIODevice::ReadOnly))
    {
        f.close();
    }
    else
    {
        r = f.write(f2.readAll()) > 0;
        f2.close();
        f.close();
    }
#else
    // pod normalnymi OS-ami nie trzeba sie gimnastykowac z atrybutami
    r = QFile::copy(subtitlesTmp, subtitles);

    // Zmiana uprawnien do pliku
    if(GlobalConfig().changePermissions())
    {
        bool validPermissions;
        int permInt = GlobalConfig().changePermissionsTo().toInt(&validPermissions, 8);

        if(validPermissions)
        {
            int perm = 0;
            perm |= (permInt & 0700) << 2;
            perm |= (permInt & 0070) << 1;
            perm |= (permInt & 0007);
            changeSubtitlesPermissions(QFile::Permissions(perm));
        }
    }
#endif

    return r;
}
Esempio n. 26
0
int main(int argc, char **argv)
{
	QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
	QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
	QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));

	bool useGui = !QNapiCli::isCliCall(argc, argv);

	regSignal();

	if(useGui)
	{
		QNapiApp app(argc, argv, true, "QNapi");

		QStringList pathList = parseArgs(argc, argv);

		QString resourceDir = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
		QTranslator cuteTranslator;
		cuteTranslator.load("qt_" + QLocale::system().name(), resourceDir);
		app.installTranslator(&cuteTranslator);
		app.setQuitOnLastWindowClosed(false);

		if(app.arguments().contains("-o") || app.arguments().contains("--options"))
		{
			app.setQuitOnLastWindowClosed(true);
			app.showSettings();
			return 0;
		}

		if(!app.isInstanceAllowed())
		{
			for(int i = 0; i < pathList.size(); i++)
				app.sendRequest(pathList[i]);
			return 0;
		}
		
		if(GlobalConfig().firstRun())
		{
			if(QMessageBox::question(0, QObject::tr("Pierwsze uruchomienie"),
					QObject::tr("To jest pierwsze uruchomienie programu QNapi. Czy chcesz go "
					"teraz skonfigurować?"), QMessageBox::Yes | QMessageBox::No )
				== QMessageBox::Yes )
			{
				app.showSettings();
			}
		}

		// Jesli podano parametry, ustawiamy tzw. batch mode
		if(pathList.size() > 0)
		{
			app.progress()->setBatchMode(true);

			QString batchLang, p;
			bool invalidLang = false;

			for(int i = 1; i < argc; i++)
			{
				p = argv[i];

				if((p == "-l") || (p == "--language"))
				{
					++i;
					if(i < argc)
					{
						batchLang = QNapiLanguage(argv[i]).toTwoLetter();
						if(batchLang.isEmpty())
							invalidLang = true;
					} else invalidLang = true;
					break;
				}
			}

			if(invalidLang)
			{
				if(QMessageBox::question(0, "QNapi", "Niepoprawny kod językowy!\n"
						"Czy chcesz pobrać napisy w domyślnym języku?",
						QMessageBox::Yes | QMessageBox::No)
					!= QMessageBox::Yes)
				{
					return 0;
				}
			}

			app.progress()->setBatchLanguage(batchLang);

			if(QFileInfo(pathList.at(0)).isDir())
			{
				if(!app.showScanDialog(pathList.at(0)))
					return 1;
			}
			else
			{
				app.progress()->enqueueFiles(pathList);
				if(!app.progress()->download()) return 1;
			}
		}

		// Jesli nie dzialamy w trybie pobierania, mozemy ew. utworzyc ikone w tray-u
		// badz pokazac okno wyboru plikow z filmami
		if(!app.progress()->isBatchMode())
		{
			// Jesli nie ma traya, od razu wyswietlamy okienko z wyborem pliku
			if(!QSystemTrayIcon::isSystemTrayAvailable())
			{
				if(!app.progress()->isBatchMode())
				{
					app.progress()->setBatchMode(true);
					if(!app.showOpenDialog())
						return 1;
				}
			}
			else // Jesli ikona w tray-u jest obsligiwana, tworzymy ja
			{
				app.createTrayIcon();
			}
		}

		return app.exec();
	}
	else
	{
		QNapiCli app(argc, argv);
		return app.exec();
	}
}
void frmOpenSubtitlesConfig::accept()
{
	GlobalConfig().setNick("OpenSubtitles", ui.leNick->text());
	GlobalConfig().setPass("OpenSubtitles", ui.lePass->text());
	QDialog::accept();
}
void frmOpenSubtitlesConfig::load()
{
	ui.leNick->setText(GlobalConfig().nick("OpenSubtitles"));
	ui.lePass->setText(GlobalConfig().pass("OpenSubtitles"));
}
Esempio n. 29
0
QNapi::QNapi(int argc, char **argv)
    : QApplication(argc, argv)
{
    m_showSettings = false;
    m_run = true;

    QStringList args = this->arguments();
/*
    for(int i=0; i<argc; ++i)
    {
        if(i==0)
            continue;
        args.append(QString(argv[i]));
    }
*/
    QString argument;

    for(int i=1; i < args.size(); ++i)
    {
        argument = args[i];
        if(argument.startsWith("file://"))
            argument = argument.remove(0, 7);

        QFileInfo fi(argument);
        if(fi.isDir())
        {
            QFileInfoList l = QDir(argument).entryInfoList(QStringList() << "*.mp4" << "*.avi" << "*.mkv" << "*.mpg" << "*.mov" << "*.vob");
            foreach(QFileInfo i, l)
                m_movies << i.absoluteFilePath();
        }
        else if(fi.isFile())
            m_movies.append(argument);

        if((argument == "-l") || (argument == "--language"))
        {
            ++i;
            if(i < args.size())
                m_lang.setLanguage(args[i]);

            if(!m_lang.isValid())
                if(QMessageBox::question(0, "QNapi", QObject::tr("Niepoprawny kod językowy!\nCzy chcesz pobrać napisy w domyślnym języku?"), QMessageBox::Yes | QMessageBox::No)
                    != QMessageBox::Yes)
                    m_run = false;
        }
    }

    if(args.contains("-o") || args.contains("--options") || m_movies.isEmpty())
    {
        m_showSettings = true;
        m_run = false;
    }
    else
    {
        if(GlobalConfig().firstRun())
        {
            if(QMessageBox::question(0, QObject::tr("Pierwsze uruchomienie"),
                    QObject::tr("To jest pierwsze uruchomienie programu QNapi. Czy chcesz go "
                    "teraz skonfigurować?"), QMessageBox::Yes | QMessageBox::No )
                == QMessageBox::Yes )
            {
                m_showSettings = true;
            }
        }
    }
}