mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-12-15 01:23:42 +00:00
@ -89,6 +89,22 @@ QString ExtScript::fileName()
|
||||
}
|
||||
|
||||
|
||||
QList<ExtScript::Filter> ExtScript::filters()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_filters;
|
||||
}
|
||||
|
||||
|
||||
bool ExtScript::hasOutput()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_output;
|
||||
}
|
||||
|
||||
|
||||
int ExtScript::interval()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -97,6 +113,14 @@ int ExtScript::interval()
|
||||
}
|
||||
|
||||
|
||||
bool ExtScript::isActive()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_active;
|
||||
}
|
||||
|
||||
|
||||
QString ExtScript::name()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -129,6 +153,28 @@ ExtScript::Redirect ExtScript::redirect()
|
||||
}
|
||||
|
||||
|
||||
QStringList ExtScript::strFilters()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QStringList value;
|
||||
for (int i=0; i<m_filters.count(); i++)
|
||||
switch (m_filters[i]) {
|
||||
case wrapAnsiColor:
|
||||
value.append(QString("color"));
|
||||
break;
|
||||
case wrapNewLine:
|
||||
value.append(QString("newline"));
|
||||
break;
|
||||
case none:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
QString ExtScript::strRedirect()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -141,6 +187,7 @@ QString ExtScript::strRedirect()
|
||||
case stderr2stdout:
|
||||
value = QString("stderr2stdout");
|
||||
break;
|
||||
case nothing:
|
||||
default:
|
||||
value = QString("nothing");
|
||||
break;
|
||||
@ -158,22 +205,6 @@ QString ExtScript::tag()
|
||||
}
|
||||
|
||||
|
||||
bool ExtScript::hasOutput()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_output;
|
||||
}
|
||||
|
||||
|
||||
bool ExtScript::isActive()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_active;
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::setApiVersion(const int _apiVersion)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -210,12 +241,21 @@ void ExtScript::setExecutable(const QString _executable)
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::setHasOutput(const bool state)
|
||||
void ExtScript::setFilters(const QList<ExtScript::Filter> _filters)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "State" << state;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Filters" << _filters;
|
||||
|
||||
m_output = state;
|
||||
m_filters = _filters;
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::setHasOutput(const bool _state)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "State" << _state;
|
||||
|
||||
m_output = _state;
|
||||
}
|
||||
|
||||
|
||||
@ -271,6 +311,19 @@ void ExtScript::setRedirect(const Redirect _redirect)
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::setStrFilters(const QStringList _filters)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Filters" << _filters;
|
||||
|
||||
for (int i=0; i<_filters.count(); i++)
|
||||
if (_filters[i] == QString("color"))
|
||||
updateFilter(wrapAnsiColor);
|
||||
else if (_filters[i] == QString("newline"))
|
||||
updateFilter(wrapNewLine);
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::setStrRedirect(const QString _redirect)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -285,6 +338,68 @@ void ExtScript::setStrRedirect(const QString _redirect)
|
||||
}
|
||||
|
||||
|
||||
QString ExtScript::applyColorFilter(QString _value)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Value" << _value;
|
||||
|
||||
// black
|
||||
_value.replace(QString("\\[\\033[0;30m\\]"), QString("<span style=\"color:#000000;\">"));
|
||||
_value.replace(QString("\\[\\033[1;30m\\]"), QString("<span style=\"color:#808080;\">"));
|
||||
// red
|
||||
_value.replace(QString("\\[\\033[0;31m\\]"), QString("<span style=\"color:#800000;\">"));
|
||||
_value.replace(QString("\\[\\033[1;31m\\]"), QString("<span style=\"color:#ff0000;\">"));
|
||||
// green
|
||||
_value.replace(QString("\\[\\033[0;32m\\]"), QString("<span style=\"color:#008000;\">"));
|
||||
_value.replace(QString("\\[\\033[1;32m\\]"), QString("<span style=\"color:#00ff00;\">"));
|
||||
// yellow
|
||||
_value.replace(QString("\\[\\033[0;33m\\]"), QString("<span style=\"color:#808000;\">"));
|
||||
_value.replace(QString("\\[\\033[1;33m\\]"), QString("<span style=\"color:#ffff00;\">"));
|
||||
// blue
|
||||
_value.replace(QString("\\[\\033[0;34m\\]"), QString("<span style=\"color:#000080;\">"));
|
||||
_value.replace(QString("\\[\\033[1;34m\\]"), QString("<span style=\"color:#0000ff;\">"));
|
||||
// purple
|
||||
_value.replace(QString("\\[\\033[0;35m\\]"), QString("<span style=\"color:#800080;\">"));
|
||||
_value.replace(QString("\\[\\033[1;35m\\]"), QString("<span style=\"color:#ff00ff;\">"));
|
||||
// cyan
|
||||
_value.replace(QString("\\[\\033[0;36m\\]"), QString("<span style=\"color:#008080;\">"));
|
||||
_value.replace(QString("\\[\\033[1;36m\\]"), QString("<span style=\"color:#00ffff;\">"));
|
||||
// white
|
||||
_value.replace(QString("\\[\\033[0;37m\\]"), QString("<span style=\"color:#c0c0c0;\">"));
|
||||
_value.replace(QString("\\[\\033[1;37m\\]"), QString("<span style=\"color:#ffffff;\">"));
|
||||
// exit
|
||||
_value.replace(QString("\\[\\033[0m\\]"), QString("</span>"));
|
||||
|
||||
return _value;
|
||||
}
|
||||
|
||||
|
||||
QString ExtScript::applyNewLineFilter(QString _value)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Value" << _value;
|
||||
|
||||
_value.replace(QString("\n"), QString("<br>"));
|
||||
|
||||
return _value;
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::updateFilter(const ExtScript::Filter _filter, const bool _add)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Filter" << _filter;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Should be added" << _add;
|
||||
|
||||
if (_add) {
|
||||
if (m_filters.contains(_filter)) return;
|
||||
m_filters.append(_filter);
|
||||
} else {
|
||||
m_filters.removeOne(_filter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::readConfiguration()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -303,6 +418,7 @@ void ExtScript::readConfiguration()
|
||||
setHasOutput(settings.value(QString("X-AW-Output"), QVariant(m_output)).toString() == QString("true"));
|
||||
setStrRedirect(settings.value(QString("X-AW-Redirect"), strRedirect()).toString());
|
||||
setInterval(settings.value(QString("X-AW-Interval"), m_interval).toInt());
|
||||
setStrFilters(settings.value(QString("X-AW-Filters"), strFilters()).toStringList());
|
||||
// api == 2
|
||||
setNumber(settings.value(QString("X-AW-Number"), m_number).toInt());
|
||||
settings.endGroup();
|
||||
@ -351,6 +467,9 @@ int ExtScript::showConfiguration()
|
||||
ui->checkBox_output->setCheckState(m_output ? Qt::Checked : Qt::Unchecked);
|
||||
ui->comboBox_redirect->setCurrentIndex(static_cast<int>(m_redirect));
|
||||
ui->spinBox_interval->setValue(m_interval);
|
||||
// filters
|
||||
ui->checkBox_colorFilter->setCheckState(m_filters.contains(wrapAnsiColor) ? Qt::Checked : Qt::Unchecked);
|
||||
ui->checkBox_linesFilter->setCheckState(m_filters.contains(wrapNewLine) ? Qt::Checked : Qt::Unchecked);
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1) return ret;
|
||||
@ -364,6 +483,9 @@ int ExtScript::showConfiguration()
|
||||
setHasOutput(ui->checkBox_output->checkState() == Qt::Checked);
|
||||
setStrRedirect(ui->comboBox_redirect->currentText());
|
||||
setInterval(ui->spinBox_interval->value());
|
||||
// filters
|
||||
updateFilter(wrapAnsiColor, ui->checkBox_colorFilter->checkState() == Qt::Checked);
|
||||
updateFilter(wrapNewLine, ui->checkBox_linesFilter->checkState() == Qt::Checked);
|
||||
|
||||
writeConfiguration();
|
||||
return ret;
|
||||
@ -404,6 +526,7 @@ void ExtScript::writeConfiguration()
|
||||
settings.setValue(QString("X-AW-Redirect"), strRedirect());
|
||||
settings.setValue(QString("X-AW-Interval"), m_interval);
|
||||
settings.setValue(QString("X-AW-Number"), m_number);
|
||||
settings.setValue(QString("X-AW-Filters"), strFilters());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
|
||||
Reference in New Issue
Block a user