Esempio n. 1
0
PgxEditor::PgxEditor(Database *database, QString editor_name)
{
    ++editor_widow_id;
    this->database = database;
    this->editor_name = editor_name;
    createActions();
    breakpointArea = new BreakPointArea(this);
    lineNumberArea = new LineNumberArea(this);
    setStyleSheet("QPlainTextEdit{background-color: white; font: bold 14px 'Courier New';}");
    highlighter = new Highlighter(document());

    toolbar = new QToolBar;
    toolbar->setIconSize(QSize(36,36));
    toolbar->setObjectName("pgxeditor");
    toolbar->setMovable(false);
    toolbar->addAction(newpgxeditor_action);
    toolbar->addAction(cut_action);
    toolbar->addAction(copy_action);
    toolbar->addAction(paste_action);
    if(!editor_name.isEmpty()) {
        toolbar->addSeparator();
        toolbar->addAction(save_action);
        toolbar->addSeparator();
        toolbar->addAction(execute_action);
    }
    toolbar->addSeparator();
    toolbar->addAction(selected_execute_action);
    toolbar->addAction(wrap_action);
    toolbar->addAction(find_action);

    pgxeditor_mainwin = new PgxEditorMainWindow;
    pgxeditor_mainwin->addToolBar(toolbar);
    pgxeditor_mainwin->setCentralWidget(this);
    pgxeditor_mainwin->setAttribute(Qt::WA_DeleteOnClose);

    find_bar = new QLineEdit;
    find_bar->setPlaceholderText(tr("Find"));
    find_bar->setVisible(false);
    pgxeditor_mainwin->statusBar()->setSizeGripEnabled(false);
    pgxeditor_mainwin->statusBar()->addPermanentWidget(casesensitivity_button, 0);
    pgxeditor_mainwin->statusBar()->addPermanentWidget(wholeword_button, 0);
    pgxeditor_mainwin->statusBar()->addPermanentWidget(backwards_button, 0);
    pgxeditor_mainwin->statusBar()->addPermanentWidget(find_bar);
    replace_bar = new QLineEdit;
    replace_bar->setPlaceholderText(tr("Replace"));
    replace_bar->setVisible(false);
    pgxeditor_mainwin->statusBar()->addPermanentWidget(replace_bar);

    connect(find_bar, SIGNAL(returnPressed()), this, SLOT(findText()));
    connect(replace_bar, SIGNAL(returnPressed()), this, SLOT(replaceText()));
    connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
    connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
    connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedSlot()));
    connect(this, SIGNAL(textChanged()), this, SLOT(textChangedSlot()));
    connect(pgxeditor_mainwin, SIGNAL(pgxeditorClosing()), this, SLOT(pgxeditorClosing()));
    updateLineNumberAreaWidth(0);
}
Esempio n. 2
0
void NumberInputWidget::setValue(float value)
{
	if (!getText().empty())
	{
		m_oldValue = getValue();
	}
	value = constraintValue(value);
	std::string text = floatToString(value, m_precision);
	if (getText() != text)
	{
		replaceText(text);
		valueChanged(this, text);
	}
}
void ScintillaEditor::changeTabsToSpaces() {
/*  -changes indentation tabs into spaces */
    //go through the text line by line and replace tabs with spaces
    QStringList editorTextLines = text().split( QRegularExpression("\n") );

    QString replaceText("");
    for (int i = 0, l = tabWidth(); i < l; i++) {
        replaceText.append(' ');
    }

    for (int i = 0, l = editorTextLines.length(); i < l; i++) {
        editorTextLines[i].replace('\t', replaceText);
    }

    setText( editorTextLines.join("\n") );
}
Esempio n. 4
0
void
FindWindow::ReplaceAll(void)
{
	// This function is called from the FinderThread function, so locking is
	// required when accessing any member variables.
	
	
	Lock();
	BString errorLog;
	
	BString findText(fFindBox->Text());
	BString replaceText(fReplaceBox->Text());
		
	if (!fIsRegEx)
	{
		findText.CharacterEscape("^$()%.[]*+-?", '\\');
	}
		
	BString replaceTerms;
	replaceTerms << "'" << findText << "' '" << replaceText << "'";
		
	ShellHelper shell;
	shell << "pwd; find ";
	shell.AddEscapedArg(fWorkingDir);
	BString sStr("'s/");
	sStr << findText.String() << "/";
	sStr << replaceText.String() << "/";
	sStr << "'";
	shell << " -type f | xargs sed -i " << sStr.String();
		
	STRACE(2,("Shell command: %s\n",shell.AsString().String()));
		
	Unlock();
	BString out;
	shell.RunInPipe(out,false);
	STRACE(2,("Command output: %s\n",out.String()));
	
	if (errorLog.CountChars() > 0)
	{
		BString errorString = B_TRANSLATE("The following files had problems replacing the search terms:\n");
		errorString << errorLog;
		
		ShowAlert(errorString.String());
	}
	
	PostMessage(M_FIND);
}
Esempio n. 5
0
void prepareDialogBox(QDialogButtonBox *box) {
    replaceText(box, QDialogButtonBox::Ok      , QPushButton::tr("OK"        , "Dialog Button"));
    replaceText(box, QDialogButtonBox::Open    , QPushButton::tr("Open"      , "Dialog Button"));
    replaceText(box, QDialogButtonBox::Save    , QPushButton::tr("Save"      , "Dialog Button"));
    replaceText(box, QDialogButtonBox::Cancel  , QPushButton::tr("Cancel"    , "Dialog Button"));
    replaceText(box, QDialogButtonBox::Close   , QPushButton::tr("Close"     , "Dialog Button"));
    replaceText(box, QDialogButtonBox::Discard , QPushButton::tr("Discard"   , "Dialog Button"));
    replaceText(box, QDialogButtonBox::Apply   , QPushButton::tr("Apply"     , "Dialog Button"));
    replaceText(box, QDialogButtonBox::Reset   , QPushButton::tr("Reset"     , "Dialog Button"));
    replaceText(box, QDialogButtonBox::RestoreDefaults, QPushButton::tr("Restore defaults", "Dialog Button"));
    replaceText(box, QDialogButtonBox::Help    , QPushButton::tr("Help"      , "Dialog Button"));
    replaceText(box, QDialogButtonBox::SaveAll , QPushButton::tr("Save All"  , "Dialog Button"));
    replaceText(box, QDialogButtonBox::Yes     , QPushButton::tr("Yes"       , "Dialog Button"));
    replaceText(box, QDialogButtonBox::YesToAll, QPushButton::tr("Yes to all", "Dialog Button"));
    replaceText(box, QDialogButtonBox::No      , QPushButton::tr("No"        , "Dialog Button"));
    replaceText(box, QDialogButtonBox::NoToAll , QPushButton::tr("No to all" , "Dialog Button"));
}
Esempio n. 6
0
ST_FUNC ST_Error ST_ID3v2_setGenre(ST_ID3v2 *tag, const uint8_t *v, size_t len,
                                   ST_TextEncoding e) {
    return replaceText(tag, ST_FrameContentType, ST_Frame22ContentType, v, len,
                       e);
}
Esempio n. 7
0
ST_FUNC ST_Error ST_ID3v2_setDate(ST_ID3v2 *tag, const uint8_t *v, size_t len,
                                  ST_TextEncoding e) {
    return replaceText(tag, ST_FrameDate, ST_Frame22Date, v, len, e);
}
Esempio n. 8
0
ST_FUNC ST_Error ST_ID3v2_setComment(ST_ID3v2 *tag, const uint8_t *v,
                                     size_t len, ST_TextEncoding e) {
    return replaceText(tag, ST_FrameComments, ST_Frame22Comments, v, len, e);
}
Esempio n. 9
0
ST_FUNC ST_Error ST_ID3v2_setAlbum(ST_ID3v2 *tag, const uint8_t *v, size_t len,
                                   ST_TextEncoding e) {
    return replaceText(tag, ST_FrameAlbumTitle, ST_Frame22AlbumTitle, v, len,
                       e);
}
Esempio n. 10
0
ST_FUNC ST_Error ST_ID3v2_setArtist(ST_ID3v2 *tag, const uint8_t *v, size_t len,
                                    ST_TextEncoding e) {
    return replaceText(tag, ST_FrameLeadPerformer, ST_Frame22LeadPerformer, v,
                       len, e);
}
Esempio n. 11
0
void
FindWindow::Replace(void) // Was REPLACEALL
{
	// This function is called from the FinderThread function, so locking is
	// required when accessing any member variables.
	
	// Just make sure you escape single quotes and underscores before constructing
	// the sed command
	
	ShowAlert(B_TRANSLATE("luare based replace all has been removed until it can be migrated from Lua"), 
		"OK", NULL, NULL, B_STOP_ALERT);
	return;
	
	Lock();
	BString errorLog;
	
	for (int32 i = 0; i < fResultList->CountItems(); i++)
	{
		BString findText(fFindBox->Text()), replaceText(fReplaceBox->Text());
		
		if (!fIsRegEx)
		{
			findText.CharacterEscape("^$()%.[]*+-?", '%');
			replaceText.CharacterEscape("%", '%');
		}
		
		findText.CharacterEscape("'", '\\');
		replaceText.CharacterEscape("'", '\\');
		
		BString replaceTerms;
		replaceTerms << "'" << findText << "' '" << replaceText << "'";
		
		GrepListItem *gitem = (GrepListItem*)fResultList->ItemAt(i);
		DPath file(gitem->GetRef());

		ShellHelper shell;
		shell << "luare" << replaceTerms;
		shell.AddEscapedArg(file.GetFullPath());
		shell.AddEscapedArg(file.GetFullPath());
printf("replace command: %s\n", shell.AsString().String());
		int32 outvalue = shell.Run();
		if (outvalue)
		{
			// append file name to list of files with error conditions and notify
			// user of problems at the end so as not to annoy them.
			errorLog << "\t" << file.GetFileName() << "\n";
		}
		
		// Allow window updates from time to time
		if (i % 5 == 0)
		{
			Unlock();
			Lock();
		}
	}
	Unlock();
	
	if (errorLog.CountChars() > 0)
	{
		BString errorString = B_TRANSLATE("The following files had problems replacing the search terms:\n");
		errorString << errorLog;
		
		BAlert *alert = new BAlert(B_TRANSLATE_SYSTEM_NAME("Paladin"), errorString.String(), B_TRANSLATE("OK"));
		alert->Go();
	}
	
	PostMessage(M_FIND);
}
Esempio n. 12
0
bool Classic::toASS(const QByteArray &txt, LibASS *ass, double fps)
{
    if (!ass)
        return false;

    bool ok = false, use_mDVD_FPS = Use_mDVD_FPS;

    const QRegExp TMPRegExp("\\d{1,2}:\\d{1,2}:\\d{1,2}\\D\\s?");
    const QRegExp MPL2RegExp("\\[\\d+\\]\\[\\d*\\]\\s?");
    const QRegExp MicroDVDRegExp("\\{\\d+\\}\\{\\d*\\}\\s?");
    QRegExp MicroDVDStylesRegExp("\\{(\\w):(.*)\\}");
    MicroDVDStylesRegExp.setMinimal(true);

    QList<SubWithoutEnd> subsWithoutEnd;

    for (const QString &line : QString(txt).remove('\r').split('\n', QString::SkipEmptyParts))
    {
        double start = 0.0, duration = 0.0;
        QString sub;
        int idx;

        if ((idx = line.indexOf(TMPRegExp)) > -1)
        {
            int h = -1, m = -1, s = -1;
            sscanf(line.toLatin1().constData() + idx, "%d:%d:%d", &h, &m, &s);
            if (h > -1 && m > -1 && s > -1)
            {
                start = h*3600 + m*60 + s;
                sub = convertLine(TMPRegExp, line);
            }
        }
        else if ((idx = line.indexOf(MPL2RegExp)) > -1)
        {
            int s = -1, e = -1;
            sscanf(line.toLatin1().constData() + idx, "[%d][%d]", &s, &e);
            if (s > -1)
            {
                for (const QString &l : convertLine(MPL2RegExp, line).split('\n'))
                {
                    if (!sub.isEmpty())
                        sub.append('\n');
                    if (!l.isEmpty())
                    {
                        switch (l.at(0).toLatin1()) {
                            case '/':
                                sub.append("{\\i1}" + l.mid(1) + "{\\i0}");
                                break;
                            case '\\':
                                sub.append("{\\b1}" + l.mid(1) + "{\\b0}");
                                break;
                            case '_':
                                sub.append("{\\u1}" + l.mid(1) + "{\\u0}");
                                break;
                            default:
                                sub.append(l);
                                break;
                        }
                    }
                }
                start = s / 10.0;
                duration = e / 10.0 - start;
            }
        }
        else if ((idx = line.indexOf(MicroDVDRegExp)) > -1)
        {
            int s = -1, e = -1;
            sscanf(line.toLatin1().constData() + idx, "{%d}{%d}", &s, &e);
            if (s > -1)
            {
                sub = convertLine(MicroDVDRegExp, line);

                if (use_mDVD_FPS && (s == 0 || s == 1))
                {
                    use_mDVD_FPS = false;
                    const double newFPS = sub.midRef(0, 6).toDouble();
                    if (newFPS > 0.0 && newFPS < 100.0)
                    {
                        fps = newFPS;
                        continue;
                    }
                }

                int pos = 0;
                while ((pos = MicroDVDStylesRegExp.indexIn(sub, pos)) != -1)
                {
                    const int matchedLength = MicroDVDStylesRegExp.matchedLength();
                    const QString styleText = MicroDVDStylesRegExp.cap(2);
                    const QChar s = MicroDVDStylesRegExp.cap(1).at(0);
                    const bool singleLine = s.isLower();
                    switch (s.toLower().toLatin1())
                    {
                        case 'c':
                            if (styleText.startsWith('$') && styleText.length() == 7)
                            {
                                replaceText(sub, pos, matchedLength, singleLine, "{\\1c&" + styleText.mid(1) + "&}", "{\\1c}");
                                continue;
                            }
                            break;
                        case 'f':
                            replaceText(sub, pos, matchedLength, singleLine, "{\\fn" + styleText + "}", "{\\fn}");
                            continue;
                        case 's':
                            replaceText(sub, pos, matchedLength, singleLine, "{\\fs" + styleText + "}", "{\\fs}");
                            continue;
                        case 'p':
                            if (!singleLine)
                            {
                                replaceText(sub, pos, matchedLength, false, "{\\pos(" + styleText + ")}", QString());
                                continue;
                            }
                            break;
                        case 'y':
                            replaceText(sub, pos, matchedLength, singleLine, "{\\" + styleText + "1}", "{\\" + styleText + "0}");
                            continue;
                    }
                    pos += MicroDVDStylesRegExp.matchedLength();
                }

                start = s / fps;
                duration = e / fps - start;
            }
        }

        if (start >= 0.0 && !sub.isEmpty())
        {
            if (duration > 0.0)
            {
                initOnce(ok, ass);
                ass->addASSEvent(Functions::convertToASS(sub), start, duration);
            }
            else
                subsWithoutEnd.append(SubWithoutEnd(start, Sub_max_s, sub));
        }
    }

    if (!subsWithoutEnd.isEmpty())
    {
        qSort(subsWithoutEnd);

        for (int i = 0; i < subsWithoutEnd.size()-1; ++i)
        {
            const unsigned diff = subsWithoutEnd.at(i+1) - subsWithoutEnd.at(i);
            if (!diff)
            {
                subsWithoutEnd[i+1] += subsWithoutEnd.at(i);
                subsWithoutEnd.removeAt(i);
                --i;
            }
            else
                subsWithoutEnd[i].setDuration(diff);
        }

        initOnce(ok, ass);
        for (const SubWithoutEnd &sub : asConst(subsWithoutEnd))
            ass->addASSEvent(Functions::convertToASS(sub.sub), sub.start, sub.duration);
    }

    return ok;
}
Esempio n. 13
0
// update the info for the connection gc
// prevInfo and prevStat are the previously set data for that account (so we don't keep setting the same thing over)
char* updateInfo(PurpleConnection *gc, char* prevInfo, char* title, char* artist, gboolean isPlaying, gboolean updateStatus)
{
	PurpleAccount* account;

	char* curAcct;
	char* statusText = NULL;
	char* servStatusText = NULL;
	const char* sid = NULL;
	const char* acctInfo = NULL;
	gboolean hasStatus = FALSE;

	account = purple_connection_get_account(gc);

	acctInfo = purple_account_get_user_info(account);

	if(acctInfo != NULL)
	{
		curAcct = g_strdup(acctInfo);
	}
	else
	{
		curAcct = g_strdup("\0");
	}

	hasStatus = getStatusText(&statusText, &servStatusText, account, &sid);

	if(isPlaying)
	{
		//replace the appropriate text
		replaceText(&curAcct, start_songText, "\0");
		replaceText(&curAcct, end_songText, "\0");
		replaceText(&curAcct, artist_replace, artist);
		replaceText(&curAcct, title_replace, title);

		//hide everything in the "no song" tag
		hideBetween(&curAcct, start_noSongText, end_noSongText);

		//and do it for the status
		if(hasStatus)
		{
			replaceText(&statusText, start_songText, "\0");
			replaceText(&statusText, end_songText, "\0");
			replaceText(&statusText, artist_replace, artist);
			replaceText(&statusText, title_replace, title);

			hideBetween(&statusText, start_noSongText, end_noSongText);
		}
	}
	else
	{
		//replace the appropriate text
		replaceText(&curAcct, start_noSongText, "\0");
		replaceText(&curAcct, end_noSongText, "\0");

		//hide everything in the song tag
		hideBetween(&curAcct, start_songText, end_songText);

		//and for the status:
		if(hasStatus)
		{
			replaceText(&statusText, start_noSongText, "\0");
			replaceText(&statusText, end_noSongText, "\0");

			hideBetween(&statusText, start_songText, end_songText);
		}
	}


	//this is so we don't update the server if we don't have to
	if(strcmp(curAcct, prevInfo) != 0)
	{
		serv_set_info(gc, curAcct);
	}
	if(hasStatus)
	{
		if(updateStatus || strcmp(statusText, servStatusText) != 0)
		{
			under_recursion = TRUE;
			purple_account_set_status(account, sid, TRUE, "message", statusText, NULL);
			under_recursion = FALSE;
		}
		g_free(statusText);
		g_free(servStatusText);
	}
	return curAcct;
}