Пример #1
0
RateSelectState QsfpModule::getRateSelectValue() {
  /* Rate select can be in one of 3 states:
   * 1. Not supported
   * 2. Rate selection using extended rate select
   * 3. Rate selection with application select tables
   *
   * We currently only support 1 and 2
   * The spec: ftp://ftp.seagate.com/sff/SFF-8636.PDF has a thorough
   * discussion of this on page 36.
   */
  uint8_t enhancedOptions =
    getSettingsValue(SffField::ENHANCED_OPTIONS, ENH_OPT_RATE_SELECT_MASK);
  uint8_t options = getSettingsValue(SffField::OPTIONS, OPT_RATE_SELECT_MASK);

  if (!enhancedOptions && !options) {
    return RateSelectState::UNSUPPORTED;
  }

  uint8_t extendedRateCompliance = getSettingsValue(
      SffField::EXTENDED_RATE_COMPLIANCE);
  if (enhancedOptions == 0b10 && (extendedRateCompliance & 0b01)) {
    return RateSelectState::EXTENDED_RATE_SELECT_V1;
  } else if (enhancedOptions == 0b10 && (extendedRateCompliance & 0b10)) {
    return RateSelectState::EXTENDED_RATE_SELECT_V2;
  } else if (enhancedOptions == 0b01) {
    return RateSelectState::APPLICATION_RATE_SELECT;
  }

  return RateSelectState::UNSUPPORTED;
}
Пример #2
0
RateSelectSetting QsfpModule::getRateSelectSettingValue(RateSelectState state) {
  /* This refers to the optimised bit rate
   * The various values here are listed in the spec:
   * ftp://ftp.seagate.com/sff/SFF-8636.PDF - page 36
   */
  if (state != RateSelectState::EXTENDED_RATE_SELECT_V1 &&
      state != RateSelectState::EXTENDED_RATE_SELECT_V2) {
    return RateSelectSetting::UNSUPPORTED;
  }

  // Each byte has settings for 4 different channels
  // Currently we only support setting them all to the same value
  // We also expect rx and tx to have the same setting
  uint8_t rateRx = getSettingsValue(SffField::RATE_SELECT_RX);
  uint8_t rateTx = getSettingsValue(SffField::RATE_SELECT_TX);
  if (rateRx != rateTx) {
    LOG(ERROR) << "Unable to retrieve rate select setting: rx(" << std::hex <<
      rateRx << " and tx(" << rateTx << ") are not equal";
    return RateSelectSetting::UNSUPPORTED;
  }

  int channelRate = rateRx & 0b11;
  if (state == RateSelectState::EXTENDED_RATE_SELECT_V2) {
    // Offset so that we can correctly index into the enum
    channelRate += 3;
  }
  return (RateSelectSetting) channelRate;
}
Пример #3
0
void SettingsNetworkForm::load()
{
    spinDown->setValue( getSettingsValue("network/speed_down").toInt() / 1024 );
    spinUp->setValue( getSettingsValue("network/speed_up").toInt() / 1024 );

    m_listProxy = Proxy::loadProxys();

    listProxys->clear();
    foreach(Proxy p,m_listProxy)
        listProxys->addItem(p.toString());
}
Пример #4
0
JVM::JVM(bool forceJreSearch) : m_jvm(0)
{
	qRegisterMetaType<JObject>("JObject");

	QString savedPath = getSettingsValue("extensions/jvm_path").toString();
	if (forceJreSearch || savedPath.isEmpty() || !QFile::exists(savedPath))
	{
		QProcess prc;

		qDebug() << "Locating the Java VM for Java-based plugins...";

		prc.start(DATA_LOCATION "/data/java/findjvm.sh", QIODevice::ReadOnly);
		prc.waitForFinished();

		int code = prc.exitCode();
		if (code == 1)
			Logger::global()->enterLogMessage("JPlugin", QObject::tr("Cannot locate a Java Runtime Environment"));
		else if (code == 2)
			Logger::global()->enterLogMessage("JPlugin", QObject::tr("Java Runtime Environment located, but no libjvm found"));
		else
		{
			QByteArray libname = prc.readAll().trimmed();
			jvmStartup(libname);
		}
	}
	else
	{
		qDebug() << "Loading JVM from the stored location:" << savedPath;
		jvmStartup(savedPath);
	}
}
Пример #5
0
void MainTab::closeTab()
{
    if(m_index >= FIXED_TAB_COUNT)
    {
        QWidget* w;

        w = widget(m_index);

        if(m_index == currentIndex())
        {
            int start;

            if(getSettingsValue("tab_onclose").toInt() == 1)
                start = m_lastIndex;
            else
                start = m_index - 1;

            for(int i=start; i>=0; i--)
            {
                if(isTabEnabled(i))
                {
                    setCurrentIndex(i);
                    break;
                }
            }
        }
        removeTab(m_index);

        delete w;
    }
}
Пример #6
0
void TranslationInterface::updatePersistentProperties()
{
    QVariantMap props;
    QLocale lc;
    const QString lang = getSettingsValue("UILanguage").toString();
    if (!lang.isEmpty())
        lc = QLocale(lang);
    if (lc.language() == QLocale::C)
        lc = QLocale(QLocale::English, QLocale::UnitedStates);
    props.insert("OS Name", m_analytics->deviceInfo().os.name);
    props.insert("UI Language", lc.name());
    props.insert("Inverted Theme", getSettingsValue("InvertedTheme"));
    props.insert("Translate on Enter", getSettingsValue("TranslateOnEnter"));
    props.insert("Paste'n'Translate", getSettingsValue("TranslateOnPaste"));
    m_analytics->setPersistentUserProperties(props);
}
Пример #7
0
void SettingsJavaPluginForm::load()
{
	treeInstalled->clear();
	treeAvailable->clear();
	treeUpdates->clear();
	m_availablePlugins.clear();

	QMap<QString,QString> packages = JVM::instance()->getPackageVersions();

	connect(m_network, SIGNAL(finished(QNetworkReply*)), this, SLOT(finished(QNetworkReply*)));
	m_network->get(QNetworkRequest(QUrl(UPDATE_URL + "Index?version=" + VERSION)));

	m_installedPlugins = JVM::instance()->getPackageVersions();

	loadInstalled();
	treeInstalled->header()->resizeSection(0, 200);
	treeAvailable->header()->resizeSection(0, 200);
	treeUpdates->header()->resizeSection(0, 200);

	JObject runtime = JClass("java.lang.Runtime").callStatic("getRuntime", JSignature().ret("java.lang.Runtime")).value<JObject>();

	labelJavaHeap->setText(QString("Java heap: %1 kB, %2 kB free")
			       .arg(runtime.call("totalMemory", JSignature().retLong()).toLongLong()/1024)
			       .arg(runtime.call("freeMemory", JSignature().retLong()).toLongLong()/1024));

	checkAutoCheck->setChecked(getSettingsValue("java/check_updates").toBool());
}
Пример #8
0
void JavaUpload::curlInit()
{
	if(m_curl)
		curl_easy_cleanup(m_curl);
	
	m_curl = curl_easy_init();
	//curl_easy_setopt(m_curl, CURLOPT_POST, true);
	if(getSettingsValue("httpftp/forbidipv6").toInt() != 0)
		curl_easy_setopt(m_curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
	curl_easy_setopt(m_curl, CURLOPT_USERAGENT, "FatRat/" VERSION);
	curl_easy_setopt(m_curl, CURLOPT_ERRORBUFFER, m_errorBuffer);
	//curl_easy_setopt(m_curl, CURLOPT_SEEKFUNCTION, seek_function);
	curl_easy_setopt(m_curl, CURLOPT_SEEKDATA, this);
	curl_easy_setopt(m_curl, CURLOPT_DEBUGDATA, this);
	curl_easy_setopt(m_curl, CURLOPT_VERBOSE, true);
	//curl_easy_setopt(m_curl, CURLOPT_PROGRESSFUNCTION, anti_crash_fun);
	curl_easy_setopt(m_curl, CURLOPT_CONNECTTIMEOUT, 10);
	curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, CurlUser::write_function);
	curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, static_cast<CurlUser*>(this));
	curl_easy_setopt(m_curl, CURLOPT_READFUNCTION, CurlUser::read_function);
	curl_easy_setopt(m_curl, CURLOPT_READDATA, static_cast<CurlUser*>(this));
	curl_easy_setopt(m_curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
	curl_easy_setopt(m_curl, CURLOPT_HEADERFUNCTION, process_header);
	curl_easy_setopt(m_curl, CURLOPT_WRITEHEADER, this);
	
	if(m_postData)
	{
		curl_formfree(m_postData);
		m_postData = 0;
	}
}
Пример #9
0
void StatsWidget::paintEvent(QPaintEvent* event)
{
	QPainter painter(this);
	painter.setRenderHint(QPainter::Antialiasing);
	
	if(event != 0)
		painter.setClipRegion(event->region());
	
	if(m_globDownPrev >= 0 && m_globDown >= 0 && height() > SPACE*2)
	{
		int tmp;
		const int colwidth = width() / 8;
		const int colheight = height()-SPACE*2;
		qint64 mydown = QueueMgr::instance()->totalDown();
		qint64 myup = QueueMgr::instance()->totalUp();
		qint64 globdown = m_globDown - m_globDownPrev;
		qint64 globup = m_globUp - m_globUpPrev;
		const int maxdown = getSettingsValue("network/speed_down").toInt();
		const int maxup = getSettingsValue("network/speed_up").toInt();
		
		globdown = qMin<qint64>(globdown, maxdown);
		globup = qMin<qint64>(globup, maxup);
		
		mydown = qMin<qint64>(mydown, globdown);
		myup = qMin<qint64>(myup, globup);
		
		painter.fillRect(colwidth, SPACE, colwidth, colheight, Qt::white);
		painter.drawRect(colwidth, SPACE, colwidth, colheight);
		
		tmp = double(colheight)/maxdown*globdown;
		painter.fillRect(colwidth, colheight+SPACE, colwidth, -tmp, Qt::black);
		tmp = double(colheight)/maxdown*mydown;
		painter.fillRect(colwidth, colheight+SPACE, colwidth, -tmp, Qt::red);
		
		painter.fillRect(width()-colwidth, SPACE, -colwidth, colheight, Qt::white);
		painter.drawRect(width()-colwidth, SPACE, -colwidth, colheight);
		
		tmp = double(colheight)/maxup*globup;
		painter.fillRect(width()-colwidth, colheight+SPACE, -colwidth, -tmp, Qt::black);
		tmp = double(colheight)/maxup*myup;
		painter.fillRect(width()-colwidth, colheight+SPACE, -colwidth, -tmp, Qt::red);
		
		painter.drawText(QRect(0, 0, colwidth*3, SPACE), Qt::AlignCenter, "down");
		painter.drawText(QRect(width()-colwidth*3, 0, colwidth*3, SPACE), Qt::AlignCenter, "up");
		painter.drawText(QRect(0, height()-SPACE, width(), SPACE), Qt::AlignCenter, m_strInterface);
	}
}
Пример #10
0
void MetalinkSettings::load()
{
	int mode = getSettingsValue("metalink/mode").toInt();
	if (mode == 0)
		radioUseHTTP->setChecked(true);
	else if (mode == 1)
		radioUseTorrent->setChecked(true);
}
Пример #11
0
void Scripting::addPresetCustomPythonPaths() {
    auto value = getSettingsValue(PYTHON_CUSTOM_PATHS);
    if (value.isNull()) { return; }
    auto customPaths = value.toStringList();
    for (const auto & customPath : customPaths) {
        addPythonPath(customPath);
    }
}
Пример #12
0
void Scripting::changeWorkingDirectory() {
    auto value = getSettingsValue(PYTHON_WORKING_DIRECTORY);
    if (value.isNull()) { return; }
    auto workingDir = value.toString();
    if (workingDir.isEmpty()) { return; }

    evalScript("import os");
    evalScript(QString("os.chdir('%1')").arg(workingDir));
}
Пример #13
0
void PreferencesDialog::fillLanguageBox()
{
    QDir translationsDir(QCoreApplication::applicationDirPath() + "/translations",
                         "sqlb_*.qm");

    QLocale systemLocale = QLocale::system();

    // Add default language
    if (systemLocale.name() == "en_US")
    {
        ui->languageComboBox->addItem(QIcon(":/flags/en_US"),
                                      "English (United States) [System Language]",
                                      "en_US");
    }
    else
    {
        ui->languageComboBox->addItem(QIcon(":/flags/en_US"),
                                      "English (United States) [Default Language]",
                                      "en_US");
    }

    foreach(const QFileInfo &file, translationsDir.entryInfoList())
    {
        QLocale locale(file.baseName().remove("sqlb_"));

        // Skip invalid locales
        if(locale.name() == "C")
            continue;

        QString language = QLocale::languageToString(locale.language()) + " (" +
                           QLocale::countryToString(locale.country()) + ")";

        if (locale == systemLocale)
            language += " [System language]";

        ui->languageComboBox->addItem(QIcon(":/flags/" + locale.name()), language, locale.name());
    }

    ui->languageComboBox->model()->sort(0);

    // Try to select the language for the stored locale
    int index = ui->languageComboBox->findData(getSettingsValue("General", "language"),
                                               Qt::UserRole, Qt::MatchExactly);

    // If there's no translation for the current locale, default to English
    if(index < 0)
        index = ui->languageComboBox->findData("en_US", Qt::UserRole, Qt::MatchExactly);

    QString chosenLanguage = ui->languageComboBox->itemText(index);
    QVariant chosenLocale = ui->languageComboBox->itemData(index);
    QIcon chosenIcon = ui->languageComboBox->itemIcon(index);

    // There's no "move" method, so we remove and add the chosen language again at the top
    ui->languageComboBox->removeItem(index);
    ui->languageComboBox->insertItem(0, chosenIcon, chosenLanguage, chosenLocale);
    ui->languageComboBox->setCurrentIndex(0);
}
Пример #14
0
bool QsfpModule::getTransceiverSettingsInfo(TransceiverSettings &settings) {
  settings.cdrTx = SffFieldInfo::getFeatureState(
      getSettingsValue(SffField::EXTENDED_IDENTIFIER, EXT_ID_CDR_TX_MASK),
      getSettingsValue(SffField::CDR_CONTROL, CDR_CONTROL_TX_MASK));
  settings.cdrRx = SffFieldInfo::getFeatureState(
      getSettingsValue(SffField::EXTENDED_IDENTIFIER, EXT_ID_CDR_RX_MASK),
      getSettingsValue(SffField::CDR_CONTROL, CDR_CONTROL_RX_MASK));

  settings.powerMeasurement = SffFieldInfo::getFeatureState(
      getSettingsValue(SffField::DIAGNOSTIC_MONITORING_TYPE,
                       POWER_MEASUREMENT_MASK));

  settings.powerControl = getPowerControlValue();
  settings.rateSelect = getRateSelectValue();
  settings.rateSelectSetting = getRateSelectSettingValue(settings.rateSelect);

  return true;
}
Пример #15
0
QueueView::QueueView(QWidget* parent) : QTreeWidget(parent), m_status(0)
{
	if(getSettingsValue("css").toBool())
	{
		QFile file;
		if(openDataFile(&file, "/data/css/queueview.css"))
			setStyleSheet(file.readAll());
	}
}
Пример #16
0
void PreferencesDialog::saveSettings()
{
    setSettingsValue("db", "defaultencoding", ui->encodingComboBox->currentText());
    setSettingsValue("db", "defaultlocation", ui->locationEdit->text());
    setSettingsValue("db", "savedefaultlocation", ui->comboDefaultLocation->currentIndex());
    setSettingsValue("db", "hideschemalinebreaks", ui->checkHideSchemaLinebreaks->isChecked());
    setSettingsValue("db", "foreignkeys", ui->foreignKeysCheckBox->isChecked());
    setSettingsValue("db", "prefetchsize", ui->spinPrefetchSize->value());
    setSettingsValue("db", "defaultsqltext", ui->editDatabaseDefaultSqlText->text());

    setSettingsValue("checkversion", "enabled", ui->checkUpdates->isChecked());

    setSettingsValue("databrowser", "font", ui->comboDataBrowserFont->currentText());
    setSettingsValue("databrowser", "fontsize", ui->spinDataBrowserFontSize->value());
    saveColorSetting(ui->fr_null_fg, "null_fg");
    saveColorSetting(ui->fr_null_bg, "null_bg");
    saveColorSetting(ui->fr_reg_fg, "reg_fg");
    saveColorSetting(ui->fr_reg_bg, "reg_bg");
    saveColorSetting(ui->fr_bin_fg, "bin_fg");
    saveColorSetting(ui->fr_bin_bg, "bin_bg");
    setSettingsValue("databrowser", "null_text", ui->txtNull->text());
    setSettingsValue("databrowser", "filter_escape", ui->editFilterEscape->text());
    setSettingsValue("databrowser", "filter_delay", ui->spinFilterDelay->value());

    for(int i=0; i < ui->treeSyntaxHighlighting->topLevelItemCount(); ++i)
    {
        QString name = ui->treeSyntaxHighlighting->topLevelItem(i)->text(0);
        setSettingsValue("syntaxhighlighter", name + "_colour", ui->treeSyntaxHighlighting->topLevelItem(i)->text(2));
        setSettingsValue("syntaxhighlighter", name + "_bold", ui->treeSyntaxHighlighting->topLevelItem(i)->checkState(3) == Qt::Checked);
        setSettingsValue("syntaxhighlighter", name + "_italic", ui->treeSyntaxHighlighting->topLevelItem(i)->checkState(4) == Qt::Checked);
        setSettingsValue("syntaxhighlighter", name + "_underline", ui->treeSyntaxHighlighting->topLevelItem(i)->checkState(5) == Qt::Checked);
    }
    setSettingsValue("editor", "font", ui->comboEditorFont->currentText());
    setSettingsValue("editor", "fontsize", ui->spinEditorFontSize->value());
    setSettingsValue("editor", "tabsize", ui->spinTabSize->value());
    setSettingsValue("log", "fontsize", ui->spinLogFontSize->value());
    setSettingsValue("editor", "auto_completion", ui->checkAutoCompletion->isChecked());
    setSettingsValue("editor", "error_indicators", ui->checkErrorIndicators->isChecked());
    setSettingsValue("editor", "horizontal_tiling", ui->checkHorizontalTiling->isChecked());

    QStringList extList;
    foreach(QListWidgetItem* item, ui->listExtensions->findItems(QString("*"), Qt::MatchWrap | Qt::MatchWildcard))
        extList.append(item->text());
    setSettingsValue("extensions", "list", extList);
    setSettingsValue("extensions", "disableregex", ui->checkRegexDisabled->isChecked());

    // Warn about restarting to change language
    QVariant newLanguage = ui->languageComboBox->itemData(ui->languageComboBox->currentIndex());
    if (newLanguage != getSettingsValue("General", "language"))
        QMessageBox::information(this, QApplication::applicationName(),
                                 tr("The language will change after you restart the application."));

    setSettingsValue("General", "language", newLanguage);

    accept();
}
Пример #17
0
PowerControlState QsfpModule::getPowerControlValue() {
  switch (static_cast<PowerControl>(getSettingsValue(
      SffField::POWER_CONTROL, uint8_t(PowerControl::POWER_CONTROL_MASK)))) {
    case PowerControl::POWER_SET_BY_HW:
      return PowerControlState::POWER_SET_BY_HW;
    case PowerControl::HIGH_POWER_OVERRIDE:
      return PowerControlState::HIGH_POWER_OVERRIDE;
    case PowerControl::POWER_OVERRIDE:
      return PowerControlState::POWER_OVERRIDE;
    default:
      return PowerControlState::POWER_LPMODE;
  }
}
Пример #18
0
void HttpFtpSettings::load()
{
	bool bFound = false;
	
	checkForbidIPv6->setChecked(getSettingsValue("httpftp/forbidipv6").toBool());
	
	// LOAD PROXYS
	m_listProxy = Proxy::loadProxys();
	m_defaultProxy = getSettingsValue("httpftp/defaultproxy").toString();
	
	comboDefaultProxy->clear();
	comboDefaultProxy->addItem(tr("None", "No proxy"));
	for(int i=0;i<m_listProxy.size();i++)
	{
		comboDefaultProxy->addItem(m_listProxy[i].toString());
		if(m_listProxy[i].uuid == m_defaultProxy)
		{
			comboDefaultProxy->setCurrentIndex(i+1);
			
			bFound = true;
		}
	}
	
	if(!bFound)
		m_defaultProxy = QUuid();
	
	// LOAD AUTHs
	m_listAuth = Auth::loadAuths();
	
	listAuths->clear();
	foreach(Auth a, m_listAuth)
		listAuths->addItem(a.strRegExp);

	lineConnectionTimeout->setText(getSettingsValue("httpftp/timeout").toString());
	checkDetectTorrents->setChecked(getSettingsValue("httpftp/detect_torrents").toBool());
#ifndef WITH_BITTORRENT
	checkDetectTorrents->setDisabled(true);
#endif
}
Пример #19
0
jobject JSettings::getValue(JNIEnv* env, jclass, jstring jname, jobject defValue)
{
	const char* def = "----jplugin-def";
	JString name(jname);
	QVariant v = getSettingsValue(name.str(), def);

	if (v.type() == QVariant::String && v.toString() == def)
		return defValue;

	JObject obj = JMap::nativeToBoxed(v);
	qDebug() << obj.getClass().getClassName();
	return obj.getLocalRef();
}
Пример #20
0
void Scripting::executeFromUserDirectory() {
    auto value = getSettingsValue(PYTHON_AUTOSTART_FOLDER);
    if (value.isNull()) { return; }
    auto autoStartFolder = value.toString();
    if (autoStartFolder.isEmpty()) { return; }

    QDir scriptDir(autoStartFolder);
    QStringList endings;
    endings << "*.py";
    scriptDir.setNameFilters(endings);
    QFileInfoList entries = scriptDir.entryInfoList();
    foreach(const QFileInfo &script, entries) {
        QFile file(script.canonicalFilePath());
        if(!file.open(QIODevice::Text | QIODevice::ReadOnly)) {
            continue;
        }
        _ctx.evalFile(script.canonicalFilePath());
    }
Пример #21
0
void TorrentDetails::openFile()
{
	if(m_selFiles.size() != 1)
		return;
	
	int i = m_selFiles[0];
	
	QString relative = QString::fromUtf8(m_download->m_info->file_at(i).path.c_str());
	QString path = m_download->dataPath(false);
	
	if(!path.endsWith('/'))
		path += '/';
	path += relative;
	
	QString command = QString("%1 \"%2\"")
			.arg(getSettingsValue("fileexec").toString())
			.arg(path);
	QProcess::startDetached(command);
}
Пример #22
0
QVariant PreferencesDialog::getSettingsDefaultValue(const QString& group, const QString& name)
{
    // db/defaultencoding?
    if(group == "db" && name == "defaultencoding")
        return "UTF-8";

    // db/savedefaultlocation?
    if(group == "db" && name == "savedefaultlocation")
        return 2;

    // db/defaultlocation?
    if(group == "db" && name == "defaultlocation")
        return QDir::homePath();

    // db/lastlocation?
    if(group == "db" && name == "lastlocation")
        return getSettingsValue("db", "defaultlocation");

    // db/hideschemalinebreaks?
    if(group == "db" && name == "hideschemalinebreaks")
        return false;

    // db/foreignkeys?
    if(group == "db" && name == "foreignkeys")
        return true;

    // db/prefetchsize?
    if(group == "db" && name == "prefetchsize")
        return 50000;

    // MainWindow/geometry?
    if(group == "MainWindow" && name == "geometry")
        return "";

    // MainWindow/windowState?
    if(group == "MainWindow" && name == "windowState")
        return "";

    // SQLLogDock/Log?
    if(group == "SQLLogDock" && name == "Log")
        return "Application";

    // General/recentFileList?
    if(group == "General" && name == "recentFileList")
        return QStringList();

    // General/language?
    if(group == "General" && name == "language")
        return QLocale::system().name();

    // checkversion/enabled
    if(group == "checkversion" && name == "enabled")
        return true;

    // Data Browser/NULL Fields
    if(group == "databrowser")
    {
        if (name == "null_text")
            return "NULL";
        if (name == "null_fg_colour")
            return QColor(Qt::lightGray).name();
        if (name == "null_bg_colour")
            return QColor(Qt::white).name();
    }

    // syntaxhighlighter?
    if(group == "syntaxhighlighter")
    {
        // Bold? Only tables, functions and keywords are bold by default
        if(name.right(4) == "bold")
            return name == "keyword_bold" || name == "table_bold" || name == "function_bold";

        // Italic? Nothing by default
        if(name.right(6) == "italic")
            return false;

        // Underline? Nothing by default
        if(name.right(9) == "underline")
            return false;

        // Colour?
        if(name.right(6) == "colour")
        {
            if(name == "keyword_colour")
                return QColor(Qt::darkBlue).name();
            else if(name == "function_colour")
                return QColor(Qt::blue).name();
            else if(name == "table_colour")
                return QColor(Qt::darkCyan).name();
            else if(name == "comment_colour")
                return QColor(Qt::darkGreen).name();
            else if(name == "identifier_colour")
                return QColor(Qt::darkMagenta).name();
            else if(name == "string_colour")
                return QColor(Qt::red).name();
            else if(name == "currentline_colour")
                return QColor(236, 236, 245).name();
        }
    }

    // editor/fontsize or log/fontsize?
    if((group == "editor" || group == "log") && name == "fontsize")
        return 9;

    if(group == "editor")
    {
        if(name == "tabsize")
        {
            return 4;
        }
    }

    // extensions/list?
    if(group == "extensions" && name == "list")
        return QStringList();

    // extensions/disableregex?
    if(group == "extension" && name == "disableregex")
        return false;

    // Unknown combination of group and name? Return an invalid QVariant!
    return QVariant();
}
Пример #23
0
void TorrentSettings::load()
{
	spinListenStart->setValue(getSettingsValue("torrent/listen_start").toInt());
	spinListenEnd->setValue(getSettingsValue("torrent/listen_end").toInt());
	spinRatio->setValue(getSettingsValue("torrent/maxratio").toDouble());
	
	spinConnections->setValue(getSettingsValue("torrent/maxconnections").toInt());
	spinUploads->setValue(getSettingsValue("torrent/maxuploads").toInt());
	spinConnectionsLocal->setValue(getSettingsValue("torrent/maxconnections_loc").toInt());
	spinUploadsLocal->setValue(getSettingsValue("torrent/maxuploads_loc").toInt());
	
	spinFiles->setValue(getSettingsValue("torrent/maxfiles").toInt());
	checkDHT->setChecked(getSettingsValue("torrent/dht").toBool());
	checkPEX->setChecked(getSettingsValue("torrent/pex").toBool());
	comboAllocation->setCurrentIndex(getSettingsValue("torrent/allocation").toInt());
	
	comboEncIncoming->setCurrentIndex(getSettingsValue("torrent/enc_incoming").toInt());
	comboEncOutgoing->setCurrentIndex(getSettingsValue("torrent/enc_outgoing").toInt());
	
	comboEncLevel->setCurrentIndex(getSettingsValue("torrent/enc_level").toInt());
	checkEncRC4Prefer->setChecked(getSettingsValue("torrent/enc_rc4_prefer").toBool());
	
	lineIP->setText(getSettingsValue("torrent/external_ip").toString());
	
	comboProxy->clear();
	comboProxy->addItem(tr("None", "No proxy"));
	
	m_listProxy = Proxy::loadProxys();
	
	QUuid uuidProxy;
	
	uuidProxy = getSettingsValue("torrent/proxy").toString();

	for(int i=0;i<m_listProxy.size();i++)
	{
		int index;
		QString name = m_listProxy[i].toString();
		
		comboProxy->addItem(name);
		index = comboProxy->count()-1;
		comboProxy->setItemData(index, m_listProxy[i].uuid.toString());
		
		if(m_listProxy[i].uuid == uuidProxy)
			comboProxy->setCurrentIndex(index);
	}
	
	checkUPNP->setChecked(getSettingsValue("torrent/mapping_upnp").toBool());
	checkNATPMP->setChecked(getSettingsValue("torrent/mapping_natpmp").toBool());
	checkLSD->setChecked(getSettingsValue("torrent/mapping_lsd").toBool());
	
	comboDetailsMode->setCurrentIndex(getSettingsValue("torrent/details_mode").toInt());
	
	QString ua = getSettingsValue("torrent/ua").toString();
	for(int i=0;i<comboUA->count();i++)
	{
		if (comboUA->itemData(i).toString() == ua)
		{
			comboUA->setCurrentIndex(i);
			break;
		}
	}
}
Пример #24
0
SpeedGraph::SpeedGraph(QWidget* parent) : QWidget(parent), m_queue(0), m_transfer(0)
{
	m_timer = new QTimer(this);
	connect(m_timer, SIGNAL(timeout()), this, SLOT(update()));
	m_timer->start(getSettingsValue("gui_refresh").toInt());
}
Пример #25
0
        if (ui->languageComboBox->findData(locale.name(), Qt::UserRole, Qt::MatchExactly) != -1)
            continue;

        QString language = QLocale::languageToString(locale.language()) + " (" +
                           QLocale::countryToString(locale.country()) + ")";

        if (locale == systemLocale)
            language += " [System language]";

        ui->languageComboBox->addItem(QIcon(":/flags/" + locale.name()), language, locale.name());
    }

    ui->languageComboBox->model()->sort(0);

    // Try to select the language for the stored locale
    int index = ui->languageComboBox->findData(getSettingsValue("General", "language"),
                                               Qt::UserRole, Qt::MatchExactly);

    // If there's no translation for the current locale, default to English
    if(index < 0)
        index = ui->languageComboBox->findData("en_US", Qt::UserRole, Qt::MatchExactly);

    QString chosenLanguage = ui->languageComboBox->itemText(index);
    QVariant chosenLocale = ui->languageComboBox->itemData(index);
    QIcon chosenIcon = ui->languageComboBox->itemIcon(index);

    // There's no "move" method, so we remove and add the chosen language again at the top
    ui->languageComboBox->removeItem(index);
    ui->languageComboBox->insertItem(0, chosenIcon, chosenLanguage, chosenLocale);
    ui->languageComboBox->setCurrentIndex(0);
}
Пример #26
0
void JVM::jvmStartup(QString libname)
{
	QLibrary lib (libname);
	cjvm_fn fn = (cjvm_fn) lib.resolve("JNI_CreateJavaVM");

	qDebug() << "libjvm found in" << libname;
	setSettingsValue("extensions/jvm_path", libname);

	if (!fn)
	{
		Logger::global()->enterLogMessage("JPlugin", QObject::tr("Failed to load the correct libjvm: %1").arg(lib.errorString()));
		return;
	}

	jint res;
	JavaVMInitArgs vm_args;
#ifdef DEBUG_BUILD
	JavaVMOption options[9];
#else
	JavaVMOption options[7];
#endif
	
	JNIEnv* env;
	QByteArray classpath = getClassPath().toUtf8();
	int mb = getSettingsValue("java/maxheap").toInt();

	if (!mb)
		mb = 16;

	classpath.prepend("-Djava.class.path=");
	qDebug() << "Java Classpath set to" << classpath;

	options[0].optionString = classpath.data();
	options[1].optionString = static_cast<char*>(alloca(24));

	snprintf(options[1].optionString, 24, "-Xmx%dm", mb);
	options[2].optionString = const_cast<char*>("-Djava.security.manager");
	options[3].optionString = const_cast<char*>("-Djava.security.policy=" DATA_LOCATION "/data/java/extension.policy");
	options[4].optionString = const_cast<char*>("-XX:+UseParNewGC");
	options[5].optionString = const_cast<char*>("-XX:MinHeapFreeRatio=5");
	options[6].optionString = const_cast<char*>("-XX:MaxHeapFreeRatio=10");
#ifdef DEBUG_BUILD
	options[7].optionString = const_cast<char*>("-Xdebug");
	options[8].optionString = const_cast<char*>("-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8222");
#endif

	vm_args.version = 0x00010006;
	vm_args.options = options;
	vm_args.nOptions = sizeof(options)/sizeof(options[0]);
	vm_args.ignoreUnrecognized = JNI_TRUE;

	res = fn(&m_jvm, (void**)&env, &vm_args);
	if (res < 0)
	{
		Logger::global()->enterLogMessage("JPlugin", QObject::tr("Failed to create a Java VM"));
		return;
	}
	JNIEnv** penv = new JNIEnv*;
	*penv = env;
	m_env.setLocalData(penv);

	if (!m_instance)
		m_instance = this;

	try
	{
		singleCObjectRegisterNatives();
		JSettings::registerNatives();
		JPlugin::registerNatives();
		JTransferPlugin::registerNatives();
		JDownloadPlugin::registerNatives();
		JBackgroundWorker::registerNatives();
		JAccountStatusPlugin::registerNatives();
	}
	catch (...)
	{
		qDebug() << "Failed to register JNI functions. This usually happens when there is an API discrepancy between the Java and the native code.\nPlease, remove ~/.local/share/fatrat/data/java/libs/fatrat-jplugins-core.jar, and try again";
		abort();
	}
}
Пример #27
0
QVariant PreferencesDialog::getSettingsDefaultValue(const QString& group, const QString& name)
{
    // db/defaultencoding?
    if(group == "db" && name == "defaultencoding")
        return "UTF-8";

    // db/savedefaultlocation?
    if(group == "db" && name == "savedefaultlocation")
        return 2;

    // db/defaultlocation?
    if(group == "db" && name == "defaultlocation")
        return QDir::homePath();

    // db/lastlocation?
    if(group == "db" && name == "lastlocation")
        return getSettingsValue("db", "defaultlocation");

    // db/hideschemalinebreaks?
    if(group == "db" && name == "hideschemalinebreaks")
        return false;

    // db/foreignkeys?
    if(group == "db" && name == "foreignkeys")
        return true;

    // db/prefetchsize?
    if(group == "db" && name == "prefetchsize")
        return 50000;

    // db/defaultsqltext?
    if(group == "db" && name == "defaultsqltext")
        return "";

    // exportcsv/firstrowheader?
    if(group == "exportcsv" && name == "firstrowheader")
        return true;

    // exportcsv/separator?
    if(group == "exportcsv" && name == "separator")
        return ',';

    // exportcsv/quotecharacter?
    if(group == "exportcsv" && name == "quotecharacter")
        return '"';

    // MainWindow/geometry?
    if(group == "MainWindow" && name == "geometry")
        return "";

    // MainWindow/windowState?
    if(group == "MainWindow" && name == "windowState")
        return "";

    // SQLLogDock/Log?
    if(group == "SQLLogDock" && name == "Log")
        return "Application";

    // General/recentFileList?
    if(group == "General" && name == "recentFileList")
        return QStringList();

    // General/language?
    if(group == "General" && name == "language")
        return QLocale::system().name();

    // checkversion/enabled
    if(group == "checkversion" && name == "enabled")
        return true;

    // Data Browser/NULL Fields
    if(group == "databrowser")
    {
        if(name == "font")
            return "Sans Serif";
        if(name == "fontsize")
            return 10;
        if(name == "null_text")
            return "NULL";
        if(name == "filter_escape")
            return "\\";
        if(name == "filter_delay")
            return 200;
        if(name == "null_fg_colour")
            return QColor(Qt::lightGray).name();
        if(name == "null_bg_colour")
            return QColor(Qt::white).name();
        if(name == "reg_fg_colour")
            return QColor(Qt::black).name();
        if(name == "reg_bg_colour")
            return QColor(Qt::white).name();
        if(name == "bin_fg_colour")
            return QColor(Qt::lightGray).name();
        if(name == "bin_bg_colour")
            return QColor(Qt::white).name();
    }

    // syntaxhighlighter?
    if(group == "syntaxhighlighter")
    {
        // Bold? Only tables, functions and keywords are bold by default
        if(name.right(4) == "bold")
            return name == "keyword_bold" || name == "table_bold" || name == "function_bold";

        // Italic? Nothing by default
        if(name.right(6) == "italic")
            return false;

        // Underline? Nothing by default
        if(name.right(9) == "underline")
            return false;

        // Colour?
        if(name.right(6) == "colour")
        {
            if(name == "keyword_colour")
                return QColor(Qt::darkBlue).name();
            else if(name == "function_colour")
                return QColor(Qt::blue).name();
            else if(name == "table_colour")
                return QColor(Qt::darkCyan).name();
            else if(name == "comment_colour")
                return QColor(Qt::darkGreen).name();
            else if(name == "identifier_colour")
                return QColor(Qt::darkMagenta).name();
            else if(name == "string_colour")
                return QColor(Qt::red).name();
            else if(name == "currentline_colour")
                return QColor(236, 236, 245).name();
        }
    }

    // editor/font?
    if(group == "editor" && name == "font")
        return "Monospace";

    // editor/fontsize or log/fontsize?
    if((group == "editor" || group == "log") && name == "fontsize")
        return 9;

    if(group == "editor")
    {
        if(name == "tabsize")
        {
            return 4;
        }
    }

    // editor/auto_completion?
    if(group == "editor" && name == "auto_completion")
        return true;

    // editor/error_indicators?
    if(group == "editor" && name == "error_indicators")
        return true;

    // editor/horizontal_tiling?
    if(group == "editor" && name == "horizontal_tiling")
        return false;

    // extensions/list?
    if(group == "extensions" && name == "list")
        return QStringList();

    // extensions/disableregex?
    if(group == "extension" && name == "disableregex")
        return false;

    // PlotDock/lineType or pointShape?
    if(group == "PlotDock")
    {
        // QCPGraph::lsLine
        if(name == "lineType")
            return 1;

        // QCPScatterStyle::ssDisk
        if(name == "pointShape")
            return 4;
    }

    // Unknown combination of group and name? Return an invalid QVariant!
    return QVariant();
}
Пример #28
0
void SpeedGraph::draw(QQueue<QPair<int,int> > data, QSize size, QPaintDevice* device, QPaintEvent* event)
{
	int top = 0;
	QPainter painter(device);
	int seconds = getSettingsValue("graphminutes").toInt()*60;
	bool bFilled = getSettingsValue("graph_style").toInt() == 0;

	painter.setRenderHint(QPainter::Antialiasing);

	if(event != 0)
	{
		painter.setClipRegion(event->region());
		painter.fillRect(event->rect(), QBrush(Qt::white));
	}
	else
		painter.fillRect(QRect(QPoint(0, 0), size), QBrush(Qt::white));

	if(!data.size())
	{
		drawNoData(size, painter);
		return;
	}

	for(int i=0;i<data.size();i++)
	{
		top = qMax(top, qMax(data[i].first,data[i].second));
	}
	if(!top || data.size()<2)
	{
		drawNoData(size, painter);
		return;
	}

	top = qMax(top/10*11,10*1024);

	const int height = size.height();
	const int width = size.width();
	const int elems = data.size();
	qreal perpt = width / (qreal(qMax(elems,seconds))-1);
	qreal pos = width;
	QVector<QLine> lines(elems);
	QVector<QPoint> filler(elems+2);

	for(int i = 0;i<data.size();i++) // download speed
	{
		float y = height-height/qreal(top)*data[elems-i-1].first;
		filler[i] = QPoint(pos, y);
		if(i > 0)
			lines[i-1] = QLine(filler[i-1], filler[i]);
		pos -= perpt;
	}
	filler[elems] = QPoint(filler[elems-1].x(), height);
	filler[elems+1] = QPoint(filler[0].x(), height);
	
	painter.setPen(Qt::darkBlue);
	
	if(bFilled)
	{
		QColor blueFill(Qt::darkBlue);
		blueFill.setAlpha(64);
		painter.setBrush(blueFill);
		painter.drawPolygon(filler.constData(), filler.size(), Qt::OddEvenFill);
	}
	
	lines[elems-1] = QLine(2,7,12,7);
	painter.drawLines(lines.constData(), lines.size());
	
	pos = width;
	for(int i = 0;i<elems;i++) // upload speed
	{
		float y = height-height/qreal(top)*data[elems-i-1].second;
		filler[i] = QPoint(pos, y);
		if(i > 0)
			lines[i-1] = QLine(filler[i-1], filler[i]);
		pos -= perpt;
	}
	filler[elems] = QPoint(filler[elems-1].x(), height);
	filler[elems+1] = QPoint(filler[0].x(), height);
	
	painter.setPen(Qt::darkRed);
	
	if(bFilled)
	{
		QColor redFill(Qt::darkRed);
		redFill.setAlpha(64);
		painter.setBrush(redFill);
		painter.drawPolygon(filler.constData(), filler.size(), Qt::OddEvenFill);
	}
	
	lines[elems-1] = QLine(2,19,12,19);
	painter.drawLines(lines.constData(), lines.size());
	
	painter.setPen(Qt::black);
	for(int i=0;i<4;i++)
	{
		int x = width-(i+1)*(width/4);
		painter.drawLine(x, height, x, height-15);
		painter.drawText(x+2, height-2, tr("%1 mins ago").arg( (seconds/4) * (i+1) / 60.0 ));
	}
	
	painter.drawText(15,12,tr("Download"));
	painter.drawText(15,24,tr("Upload"));
	
	for(int i=1;i<10;i++)
	{
		int pos = int( float(height)/10.f*i );
		
		painter.setPen(QPen(Qt::gray, 1.0, Qt::DashLine));
		painter.drawLine(0,pos,width,pos);
		
		painter.setPen(Qt::black);
		painter.drawText(0,pos-10,formatSize( qulonglong( top/10.f*(10-i) ), true));
	}
}
Пример #29
0
void PreferencesDialog::loadSettings()
{
    ui->encodingComboBox->setCurrentIndex(ui->encodingComboBox->findText(getSettingsValue("db", "defaultencoding").toString(), Qt::MatchFixedString));
    ui->comboDefaultLocation->setCurrentIndex(getSettingsValue("db", "savedefaultlocation").toInt());
    ui->locationEdit->setText(getSettingsValue("db", "defaultlocation").toString());
    ui->checkUpdates->setChecked(getSettingsValue("checkversion", "enabled").toBool());
    ui->checkHideSchemaLinebreaks->setChecked(getSettingsValue("db", "hideschemalinebreaks").toBool());
    ui->foreignKeysCheckBox->setChecked(getSettingsValue("db", "foreignkeys").toBool());
    ui->spinPrefetchSize->setValue(getSettingsValue("db", "prefetchsize").toInt());

    QPalette palette = ui->frameNullBgColour->palette();
    palette.setColor(ui->frameNullBgColour->backgroundRole(),
                     QColor(getSettingsValue("databrowser", "null_bg_colour").toString()));
    ui->frameNullBgColour->setPalette(palette);

    palette = ui->frameNullFgColour->palette();
    palette.setColor(ui->frameNullFgColour->backgroundRole(),
                     QColor(getSettingsValue("databrowser", "null_fg_colour").toString()));
    ui->frameNullFgColour->setPalette(palette);

    ui->txtNull->setText(getSettingsValue("databrowser", "null_text").toString());

    for(int i=0; i < ui->treeSyntaxHighlighting->topLevelItemCount(); ++i)
    {
        QString name = ui->treeSyntaxHighlighting->topLevelItem(i)->text(0);
        QString colorname = getSettingsValue("syntaxhighlighter", name + "_colour").toString();
        QColor color = QColor(colorname);
        ui->treeSyntaxHighlighting->topLevelItem(i)->setTextColor(2, color);
        ui->treeSyntaxHighlighting->topLevelItem(i)->setBackgroundColor(2, color);
        ui->treeSyntaxHighlighting->topLevelItem(i)->setText(2, colorname);
        if (name != "null") {
            ui->treeSyntaxHighlighting->topLevelItem(i)->setCheckState(3, getSettingsValue("syntaxhighlighter", name + "_bold").toBool() ? Qt::Checked : Qt::Unchecked);
            ui->treeSyntaxHighlighting->topLevelItem(i)->setCheckState(4, getSettingsValue("syntaxhighlighter", name + "_italic").toBool() ? Qt::Checked : Qt::Unchecked);
            ui->treeSyntaxHighlighting->topLevelItem(i)->setCheckState(5, getSettingsValue("syntaxhighlighter", name + "_underline").toBool() ? Qt::Checked : Qt::Unchecked);
        }
    }
    ui->spinEditorFontSize->setValue(getSettingsValue("editor", "fontsize").toInt());
    ui->spinTabSize->setValue(getSettingsValue("editor", "tabsize").toInt());
    ui->spinLogFontSize->setValue(getSettingsValue("log", "fontsize").toInt());

    ui->listExtensions->addItems(getSettingsValue("extensions", "list").toStringList());
    ui->checkRegexDisabled->setChecked(getSettingsValue("extensions", "disableregex").toBool());
    fillLanguageBox();
}
Пример #30
0
void PreferencesDialog::loadSettings()
{
    ui->encodingComboBox->setCurrentIndex(ui->encodingComboBox->findText(getSettingsValue("db", "defaultencoding").toString(), Qt::MatchFixedString));
    ui->comboDefaultLocation->setCurrentIndex(getSettingsValue("db", "savedefaultlocation").toInt());
    ui->locationEdit->setText(getSettingsValue("db", "defaultlocation").toString());
    ui->checkUpdates->setChecked(getSettingsValue("checkversion", "enabled").toBool());
    ui->checkHideSchemaLinebreaks->setChecked(getSettingsValue("db", "hideschemalinebreaks").toBool());
    ui->foreignKeysCheckBox->setChecked(getSettingsValue("db", "foreignkeys").toBool());
    ui->spinPrefetchSize->setValue(getSettingsValue("db", "prefetchsize").toInt());
    ui->editDatabaseDefaultSqlText->setText(getSettingsValue("db", "defaultsqltext").toString());

    ui->comboDataBrowserFont->setCurrentIndex(ui->comboEditorFont->findText(getSettingsValue("databrowser", "font").toString()));
    ui->spinDataBrowserFontSize->setValue(getSettingsValue("databrowser", "fontsize").toInt());
    loadColorSetting(ui->fr_null_fg, "null_fg");
    loadColorSetting(ui->fr_null_bg, "null_bg");
    loadColorSetting(ui->fr_reg_fg, "reg_fg");
    loadColorSetting(ui->fr_reg_bg, "reg_bg");
    loadColorSetting(ui->fr_bin_fg, "bin_fg");
    loadColorSetting(ui->fr_bin_bg, "bin_bg");

    ui->txtNull->setText(getSettingsValue("databrowser", "null_text").toString());
    ui->editFilterEscape->setText(getSettingsValue("databrowser", "filter_escape").toString());
    ui->spinFilterDelay->setValue(getSettingsValue("databrowser", "filter_delay").toInt());

    for(int i=0; i < ui->treeSyntaxHighlighting->topLevelItemCount(); ++i)
    {
        QString name = ui->treeSyntaxHighlighting->topLevelItem(i)->text(0);
        QString colorname = getSettingsValue("syntaxhighlighter", name + "_colour").toString();
        QColor color = QColor(colorname);
        ui->treeSyntaxHighlighting->topLevelItem(i)->setTextColor(2, color);
        ui->treeSyntaxHighlighting->topLevelItem(i)->setBackgroundColor(2, color);
        ui->treeSyntaxHighlighting->topLevelItem(i)->setText(2, colorname);
        if (name != "null") {
            ui->treeSyntaxHighlighting->topLevelItem(i)->setCheckState(3, getSettingsValue("syntaxhighlighter", name + "_bold").toBool() ? Qt::Checked : Qt::Unchecked);
            ui->treeSyntaxHighlighting->topLevelItem(i)->setCheckState(4, getSettingsValue("syntaxhighlighter", name + "_italic").toBool() ? Qt::Checked : Qt::Unchecked);
            ui->treeSyntaxHighlighting->topLevelItem(i)->setCheckState(5, getSettingsValue("syntaxhighlighter", name + "_underline").toBool() ? Qt::Checked : Qt::Unchecked);
        }
    }
    ui->comboEditorFont->setCurrentIndex(ui->comboEditorFont->findText(getSettingsValue("editor", "font").toString()));
    ui->spinEditorFontSize->setValue(getSettingsValue("editor", "fontsize").toInt());
    ui->spinTabSize->setValue(getSettingsValue("editor", "tabsize").toInt());
    ui->spinLogFontSize->setValue(getSettingsValue("log", "fontsize").toInt());
    ui->checkAutoCompletion->setChecked(getSettingsValue("editor", "auto_completion").toBool());
    ui->checkErrorIndicators->setChecked(getSettingsValue("editor", "error_indicators").toBool());
    ui->checkHorizontalTiling->setChecked(getSettingsValue("editor", "horizontal_tiling").toBool());

    ui->listExtensions->addItems(getSettingsValue("extensions", "list").toStringList());
    ui->checkRegexDisabled->setChecked(getSettingsValue("extensions", "disableregex").toBool());
    fillLanguageBox();
}