Esempio n. 1
0
void KLocaleConfigNumber::save()
{
    // temperary use of our locale as the global locale
    KLocale *lsave = KGlobal::_locale;
    KGlobal::_locale = m_locale;

    KConfig *config = KGlobal::config();
    KConfigGroupSaver saver(config, "Locale");

    KSimpleConfig ent(locate("locale", QString::fromLatin1("l10n/%1/entry.desktop").arg(m_locale->country())), true);
    ent.setGroup("KCM Locale");

    QString str;

    str = ent.readEntry("DecimalSymbol", QString::fromLatin1("."));
    config->deleteEntry("DecimalSymbol", false, true);
    if(str != m_locale->decimalSymbol())
        config->writeEntry("DecimalSymbol", m_locale->decimalSymbol(), true, true);

    str = ent.readEntry("ThousandsSeparator", QString::fromLatin1(","));
    config->deleteEntry("ThousandsSeparator", false, true);
    str.replace(QString::fromLatin1("$0"), QString::null);
    if(str != m_locale->thousandsSeparator())
        config->writeEntry("ThousandsSeparator", QString::fromLatin1("$0%1$0").arg(m_locale->thousandsSeparator()), true, true);

    str = ent.readEntry("PositiveSign");
    config->deleteEntry("PositiveSign", false, true);
    if(str != m_locale->positiveSign())
        config->writeEntry("PositiveSign", m_locale->positiveSign(), true, true);

    str = ent.readEntry("NegativeSign", QString::fromLatin1("-"));
    config->deleteEntry("NegativeSign", false, true);
    if(str != m_locale->negativeSign())
        config->writeEntry("NegativeSign", m_locale->negativeSign(), true, true);

    // restore the old global locale
    KGlobal::_locale = lsave;
}
Esempio n. 2
0
void ToolConfig::removeTool()
{
    //KILE_DEBUG() << "==ToolConfig::removeTool()=====================" << endl;
    if ( KMessageBox::warningContinueCancel(this, i18n("Are you sure you want to remove the tool %1?").arg(m_current)) == KMessageBox::Continue )
    {
        KConfig *config = m_config;
        QStringList cfgs = KileTool::configNames(m_current, config);
        for ( uint i = 0; i < cfgs.count(); ++i)
        {
            config->deleteGroup(KileTool::groupFor(m_current, cfgs[i]));
        }
        config->setGroup("Tools");
        config->deleteEntry(m_current);
        int index = m_configWidget->m_lstbTools->currentItem()-1;
        if ( index < 0 ) index=0;
        QString tool = m_configWidget->m_lstbTools->text(index);
        m_configWidget->m_lstbTools->blockSignals(true);
        updateToollist();
        m_configWidget->m_lstbTools->setCurrentItem(index);
        switchTo(tool, false);
        m_configWidget->m_lstbTools->blockSignals(false);
    }
}
Esempio n. 3
0
// This function is simply a wrapper to establish the connection
// to the server.  It's a bit more complicated than ::connect
// because we first have to check to see if the user specified
// a port, and if so use it, otherwise we check to see if there
// is a port specified in /etc/services, and if so use that
// otherwise as a last resort use the supplied default port.
bool TCPSlaveBase::connectToHost(const QString &host, unsigned int _port, bool sendError)
{
    unsigned short int p;
    KExtendedSocket ks;

    d->userAborted = false;

    //  - leaving SSL - warn before we even connect
    if(metaData("main_frame_request") == "TRUE" && metaData("ssl_activate_warnings") == "TRUE" && metaData("ssl_was_in_use") == "TRUE" && !m_bIsSSL)
    {
        KSSLSettings kss;
        if(kss.warnOnLeave())
        {
            int result =
                messageBox(i18n("You are about to leave secure "
                                "mode. Transmissions will no "
                                "longer be encrypted.\nThis "
                                "means that a third party could "
                                "observe your data in transit."),
                           WarningContinueCancel, i18n("Security Information"), i18n("C&ontinue Loading"), QString::null, "WarnOnLeaveSSLMode");

            // Move this setting into KSSL instead
            KConfig *config = new KConfig("kioslaverc");
            config->setGroup("Notification Messages");

            if(!config->readBoolEntry("WarnOnLeaveSSLMode", true))
            {
                config->deleteEntry("WarnOnLeaveSSLMode");
                config->sync();
                kss.setWarnOnLeave(false);
                kss.save();
            }
            delete config;

            if(result == KMessageBox::Cancel)
            {
                d->userAborted = true;
                return false;
            }
        }
    }

    d->status = -1;
    d->host = host;
    d->needSSLHandShake = m_bIsSSL;
    p = port(_port);
    ks.setAddress(host, p);
    if(d->timeout > -1)
        ks.setTimeout(d->timeout);

    if(ks.connect() < 0)
    {
        d->status = ks.status();
        if(sendError)
        {
            if(d->status == IO_LookupError)
                error(ERR_UNKNOWN_HOST, host);
            else if(d->status != -1)
                error(ERR_COULD_NOT_CONNECT, host);
        }
        return false;
    }

    m_iSock = ks.fd();

    // store the IP for later
    const KSocketAddress *sa = ks.peerAddress();
    if(sa)
        d->ip = sa->nodeName();
    else
        d->ip = "";

    ks.release(); // KExtendedSocket no longer applicable

    if(d->block != ks.blockingMode())
        ks.setBlockingMode(d->block);

    m_iPort = p;

    if(m_bIsSSL && !d->useSSLTunneling)
    {
        if(!doSSLHandShake(sendError))
            return false;
    }
    else
        setMetaData("ssl_in_use", "FALSE");

    // Since we want to use stdio on the socket,
    // we must fdopen it to get a file pointer,
    // if it fails, close everything up
    if((fp = KDE_fdopen(m_iSock, "w+")) == 0)
    {
        closeDescriptor();
        return false;
    }

    return true;
}
Esempio n. 4
0
/******************************************************************************
* If the preferences were written by a previous version of KAlarm, do any
* necessary conversions.
*/
void Preferences::convertOldPrefs()
{
    KConfig *config = KGlobal::config();
    config->setGroup(GENERAL_SECTION);
    int version = KAlarm::getVersionNumber(config->readEntry(VERSION_NUM));
    if(version >= KAlarm::Version(1, 4, 22))
        return;     // config format is up to date

    if(version <= KAlarm::Version(1, 4, 21))
    {
        // Convert KAlarm 1.4.21 preferences
        static const QString OLD_REMIND_UNITS = QString::fromLatin1("DefRemindUnits");
        config->setGroup(DEFAULTS_SECTION);
        int intUnit     = config->readNumEntry(OLD_REMIND_UNITS, 0);
        QString strUnit = (intUnit == 1) ? QString::fromLatin1("Days")
                          : (intUnit == 2) ? QString::fromLatin1("Weeks")
                          :                  QString::fromLatin1("HoursMinutes");
        config->deleteEntry(OLD_REMIND_UNITS);
        config->writeEntry(DEF_REMIND_UNITS, strUnit);
    }

    if(version <= KAlarm::Version(1, 4, 20))
    {
        // Convert KAlarm 1.4.20 preferences
        static const QString VIEW_SECTION = QString::fromLatin1("View");
        static const QString SHOW_ARCHIVED_ALARMS = QString::fromLatin1("ShowArchivedAlarms");
        static const QString SHOW_EXPIRED_ALARMS  = QString::fromLatin1("ShowExpiredAlarms");
        static const QString SHOW_ALARM_TIME      = QString::fromLatin1("ShowAlarmTime");
        static const QString SHOW_TIME_TO_ALARM   = QString::fromLatin1("ShowTimeToAlarm");
        config->setGroup(GENERAL_SECTION);
        bool showExpired = config->readBoolEntry(SHOW_EXPIRED_ALARMS, false);
        bool showTime    = config->readBoolEntry(SHOW_ALARM_TIME, true);
        bool showTimeTo  = config->readBoolEntry(SHOW_TIME_TO_ALARM, false);
        config->deleteEntry(SHOW_EXPIRED_ALARMS);
        config->deleteEntry(SHOW_ALARM_TIME);
        config->deleteEntry(SHOW_TIME_TO_ALARM);
        config->setGroup(VIEW_SECTION);
        config->writeEntry(SHOW_ARCHIVED_ALARMS, showExpired);
        config->writeEntry(SHOW_ALARM_TIME, showTime);
        config->writeEntry(SHOW_TIME_TO_ALARM, showTimeTo);
    }

    if(version <= KAlarm::Version(1, 4, 5))
    {
        // Convert KAlarm 1.4.5 preferences
        static const QString DEF_SOUND = QString::fromLatin1("DefSound");
        config->setGroup(DEFAULTS_SECTION);
        bool sound = config->readBoolEntry(DEF_SOUND, false);
        if(!sound)
            config->writeEntry(DEF_SOUND_TYPE, SoundPicker::NONE);
        config->deleteEntry(DEF_SOUND);
    }

    if(version < KAlarm::Version(1, 3, 0))
    {
        // Convert KAlarm pre-1.3 preferences
        static const QString EMAIL_ADDRESS             = QString::fromLatin1("EmailAddress");
        static const QString EMAIL_USE_CTRL_CENTRE     = QString::fromLatin1("EmailUseControlCenter");
        static const QString EMAIL_BCC_USE_CTRL_CENTRE = QString::fromLatin1("EmailBccUseControlCenter");
        QMap<QString, QString> entries = config->entryMap(GENERAL_SECTION);
        if(entries.find(EMAIL_FROM) == entries.end()
                &&  entries.find(EMAIL_USE_CTRL_CENTRE) != entries.end())
        {
            // Preferences were written by KAlarm pre-1.2.1
            config->setGroup(GENERAL_SECTION);
            bool useCC = false;
            bool bccUseCC = false;
            const bool default_emailUseControlCentre    = true;
            const bool default_emailBccUseControlCentre = true;
            useCC = config->readBoolEntry(EMAIL_USE_CTRL_CENTRE, default_emailUseControlCentre);
            // EmailBccUseControlCenter was missing in preferences written by KAlarm pre-0.9.5
            bccUseCC = config->hasKey(EMAIL_BCC_USE_CTRL_CENTRE)
                       ? config->readBoolEntry(EMAIL_BCC_USE_CTRL_CENTRE, default_emailBccUseControlCentre)
                       : useCC;
            config->writeEntry(EMAIL_FROM, (useCC ? FROM_CONTROL_CENTRE : config->readEntry(EMAIL_ADDRESS)));
            config->writeEntry(EMAIL_BCC_ADDRESS, (bccUseCC ? FROM_CONTROL_CENTRE : config->readEntry(EMAIL_BCC_ADDRESS)));
            config->deleteEntry(EMAIL_ADDRESS);
            config->deleteEntry(EMAIL_BCC_USE_CTRL_CENTRE);
            config->deleteEntry(EMAIL_USE_CTRL_CENTRE);
        }
        // Convert KAlarm 1.2 preferences
        static const QString DEF_CMD_XTERM = QString::fromLatin1("DefCmdXterm");
        config->setGroup(DEFAULTS_SECTION);
        if(config->hasKey(DEF_CMD_XTERM))
        {
            config->writeEntry(DEF_CMD_LOG_TYPE,
                               (config->readBoolEntry(DEF_CMD_XTERM, false) ? EditAlarmDlg::EXEC_IN_TERMINAL : EditAlarmDlg::DISCARD_OUTPUT));
            config->deleteEntry(DEF_CMD_XTERM);
        }
    }
    config->setGroup(GENERAL_SECTION);
    config->writeEntry(VERSION_NUM, KALARM_VERSION);
    config->sync();
}
Esempio n. 5
0
void TopLevel::config()
{
  if (!confdlg) {
    confdlg = new KDialogBase(KDialogBase::Plain, i18n("Configure Tea Cooker"),
                              KDialogBase::Ok|KDialogBase::Cancel|KDialogBase::Help,
                              KDialogBase::Ok, this, "config", true);
    QWidget *page = confdlg->plainPage();
    // FIXME: enforce sensible initial/default size of dialog
    // FIXME: modal is ok, but can avoid always-on-top?

    QBoxLayout *top_box = new QVBoxLayout(page, 0, 8);    // whole config-stuff
    QBoxLayout *box = new QHBoxLayout(top_box);           // list + properties

    /* left side - tea list and list-modifying buttons */
    QBoxLayout *leftside = new QVBoxLayout(box);
    QGroupBox *listgroup = new QGroupBox(2, Vertical, i18n("Tea List"), page);
    leftside->addWidget(listgroup, 0, 0);

    listbox = new QListView(listgroup, "listBox");
    listbox->addColumn(i18n("Name"));
    listbox->header()->setClickEnabled(false, listbox->header()->count()-1);
    listbox->addColumn(i18n("Time"));
    listbox->header()->setClickEnabled(false, listbox->header()->count()-1);
    listbox->setSorting(-1);
    connect(listbox, SIGNAL(selectionChanged()), SLOT(listBoxItemSelected()));

    // now buttons for editing the tea-list
    QWidget *listgroup_widget = new QWidget(listgroup);
    QBoxLayout *hbox = new QHBoxLayout(listgroup_widget);
    hbox->setSpacing(4);
    btn_new = new QPushButton(QString::null, listgroup_widget);
    QToolTip::add(btn_new, i18n("New"));
    btn_new->setPixmap(SmallIcon("filenew"));
    btn_new->setMinimumSize(btn_new->sizeHint() * 1.2);
    connect(btn_new, SIGNAL(clicked()), SLOT(newButtonClicked()));
    hbox->addWidget(btn_new);

    btn_del = new QPushButton(QString::null, listgroup_widget);
    QToolTip::add(btn_del, i18n("Delete"));
    btn_del->setIconSet(SmallIconSet("editdelete"));
    btn_del->setMinimumSize(btn_new->sizeHint() * 1.2);
    connect(btn_del, SIGNAL(clicked()), SLOT(delButtonClicked()));
    hbox->addWidget(btn_del);

    btn_up = new QPushButton(QString::null, listgroup_widget);
    QToolTip::add(btn_up, i18n("Up"));
    btn_up->setIconSet(SmallIconSet("up"));
    btn_up->setMinimumSize(btn_up->sizeHint() * 1.2);
    connect(btn_up, SIGNAL(clicked()), SLOT(upButtonClicked()));
    hbox->addWidget(btn_up);

    btn_down = new QPushButton(QString::null, listgroup_widget);
    QToolTip::add(btn_down, i18n("Down"));
    btn_down->setIconSet(SmallIconSet("down"));
    btn_down->setMinimumSize(btn_down->sizeHint() * 1.2);
    connect(btn_down, SIGNAL(clicked()), SLOT(downButtonClicked()));
    hbox->addWidget(btn_down);

    hbox->addStretch(10);

    /* right side - tea properties */
    QBoxLayout *rightside = new QVBoxLayout(box);
    editgroup = new QGroupBox(2, Vertical, i18n("Tea Properties"), page);
    rightside->addWidget(editgroup, 0, 0);
    QHBox *propbox = new QHBox(editgroup);

    // FIXME: - must enforce correct vertical alignment of each label-editor pair
    //          (better use one HBox for each label-editor pair?)
    QVBox *propleft = new QVBox(propbox);
    QVBox *propright = new QVBox(propbox);
    nameEdit = new QLineEdit(propright);
    nameEdit->setFixedHeight(nameEdit->sizeHint().height());
    nameEdit->setAlignment(QLineEdit::AlignLeft);
    QLabel *l = new QLabel(nameEdit, i18n("Name:"), propleft);
    l->setFixedSize(l->sizeHint());
    connect(nameEdit, SIGNAL(textChanged(const QString&)), SLOT(nameEditTextChanged(const QString&)) );

    timeEdit = new TimeEdit(propright);
    timeEdit->setFixedHeight(timeEdit->sizeHint().height());
    l = new QLabel(timeEdit, i18n("Tea time:"), propleft);
    l->setFixedSize(l->sizeHint());
    connect(timeEdit, SIGNAL(valueChanged(int)), SLOT(spinBoxValueChanged(int)));

    /* bottom - timeout actions */
    QGroupBox *actiongroup = new QGroupBox(4, Vertical, i18n("Action"), page);
    top_box->addWidget(actiongroup, 0, 0);

    QWidget *actionconf_widget = new QWidget(actiongroup);
    QBoxLayout *actionconf_hbox = new QHBoxLayout(actionconf_widget);
    btn_conf = new QPushButton(i18n("Configure Events..."), actionconf_widget);
    actionconf_hbox->addWidget(btn_conf);
    connect(btn_conf, SIGNAL(clicked()), SLOT(confButtonClicked()));
    actionconf_hbox->addStretch(10);

    eventEnable = new QCheckBox(i18n("Event"), actiongroup);
    popupEnable = new QCheckBox(i18n("Popup"), actiongroup);
    eventEnable->setFixedHeight(eventEnable->sizeHint().height());
    popupEnable->setFixedHeight(popupEnable->sizeHint().height());

    QHBox *actionbox = new QHBox(actiongroup);
    actionEnable = new QCheckBox(actionbox);
//    FIXME: add text to this line:
//    QLabel *actionLabel = new QLabel(i18n("Execute: "), actiongroup);
    actionEdit = new QLineEdit(actionbox);
    actionEdit->setFixedHeight(actionEdit->sizeHint().height());
    QToolTip::add(actionEdit, i18n("Enter command here; '%t' will be replaced with name of steeping tea"));
    connect(actionEnable, SIGNAL(toggled(bool)), SLOT(actionEnableToggled(bool)));
    rightside->addStretch();

    // single checkbox
    visEnable = new QCheckBox(i18n("Visualize progress in icon tray"), page);
    top_box->addWidget(visEnable, 0, 0);


    // let listbox claim all remaining vertical space
    top_box->setStretchFactor(box, 10);

    connect(confdlg, SIGNAL(helpClicked()), SLOT(help()));
  }

  // now add all defined teas (and their times) to the listview
  // this is done backwards because QListViewItems are inserted at the top
  listbox->clear();
  for (int i=teas.count()-1; i>=0; i--) {
    TeaListItem *item = new TeaListItem(listbox);
    item->setName(teas[i].name);
    item->setTime(teas[i].time);
    if ((unsigned int)i == current_selected)
      current_item = item;
  }

  // select first entry in listbox; if no entries present then disable right side
  if (listempty) {
    enable_controls();
    disable_properties();
    nameEdit->setText("");
    timeEdit->setValue(1);
  } else {
    listbox->setSelected(listbox->firstChild(), true);
  }

  // -------------------------

  eventEnable->setChecked(useNotify);
  popupEnable->setChecked(usePopup);
  actionEnable->setChecked(useAction);
  actionEdit->setText(action);
  actionEdit->setEnabled(useAction);
  visEnable->setChecked(useTrayVis);

  if (confdlg->exec() == QDialog::Accepted)
  {
    // activate new settings
    useNotify = eventEnable->isChecked();
    usePopup = popupEnable->isChecked();
    useAction = actionEnable->isChecked();
    action = actionEdit->text();
    useTrayVis = visEnable->isChecked();

    teas.clear();

    // Copy over teas and times from the QListView
    int i = 0;
    teas.clear();
    teas.resize(listbox->childCount());
    for (QListViewItemIterator it(listbox); it.current() != 0; ++it) {
      teas[i].name = static_cast<TeaListItem *>(it.current())->name();
      teas[i].time = static_cast<TeaListItem *>(it.current())->time();
      if (it.current() == current_item)
        current_selected = i;
      i++;
    }

    listempty = (teas.count() == 0);

    rebuildTeaMenus();

    // and store to config
    KConfig *config = kapp->config();
    // remove old-style entries from default-group (if present)
    if (config->hasKey("UserTea"))
      config->deleteEntry("UserTea");

    config->setGroup("General");
    config->writeEntry("Beep", useNotify);
    config->writeEntry("Popup", usePopup);
    config->writeEntry("UseAction", useAction);
    config->writeEntry("Action", action);
    config->writeEntry("Tea", current_selected);
    config->writeEntry("UseTrayVis", useTrayVis);
    // first get rid of all previous tea-entries from config, then write anew
    config->deleteGroup("Teas", true);          // deep remove of whole group
    config->setGroup("Teas");
    config->writeEntry("Number", teas.count());
    QString key;
    int index = 1;
    for (QValueVector<tea_struct>::ConstIterator it = teas.begin(); it != teas.end(); ++it) {
      key.sprintf("Tea%d Name", index);
      config->writeEntry(key, it->name);
      key.sprintf("Tea%d Time", index);
      config->writeEntry(key, it->time);
      index++;
    }

    config->sync();
  }
}