Exemplo n.º 1
0
void GpgGen::accept()
{
    edtName->setEnabled(false);
    cmbMail->setEnabled(false);
    edtComment->setEnabled(false);
    buttonOk->setEnabled(false);
    lblProcess->setText(i18n("Move mouse for generate random key"));
#ifdef WIN32
    QString gpg  = m_cfg->edtGPG->text();
#else
QString gpg  = QFile::decodeName(GpgPlugin::plugin->GPG());
#endif
    QString home = m_cfg->edtHome->text();
    if (gpg.isEmpty() || home.isEmpty())
        return;
    if (home[(int)(home.length() - 1)] == '\\')
        home = home.left(home.length() - 1);
    string in =
        "Key-Type: 1" CRLF
        "Key-Length: 1024" CRLF
        "Expire-Date: 0" CRLF
        "Name-Real: ";
    in += toLatin(edtName->text());
    in += CRLF;
    if (!edtComment->text().isEmpty()){
        in += "Name-Comment: ";
        in += toLatin(edtComment->text());
        in += CRLF;
    }
    in += "Name-Email: ";
    in += toLatin(cmbMail->lineEdit()->text());
    in += CRLF;
    if (!edtPass1->text().isEmpty()){
        in += "Passphrase: ";
        in += edtPass1->text().utf8();
        in += CRLF;
    }
#ifdef WIN32
    QString fname = QFile::decodeName(user_file("keys\\genkey.txt").c_str());
#else
    QString fname = QFile::decodeName(user_file("keys/genkey.txt").c_str());
#endif
    QFile f(fname);
    f.open(IO_WriteOnly | IO_Truncate);
    f.writeBlock(in.c_str(), in.length());
    f.close();

    gpg = QString("\"") + gpg + "\"";
    gpg += " --no-tty --homedir \"";
    gpg += home;
    gpg += "\" ";
    gpg += GpgPlugin::plugin->getGenKey();
    gpg += " \"";
    gpg += fname.local8Bit();
    gpg += "\"";
    m_exec = new Exec;
    connect(m_exec, SIGNAL(ready(Exec*,int,const char*)), this, SLOT(genKeyReady(Exec*,int,const char*)));
    m_exec->execute(gpg.local8Bit(), "");
}
Exemplo n.º 2
0
void History::add(Message *msg, const char *type)
{
    string line = "[";
    line += type;
    line += "]\n";
    line += msg->save();

    if (msg->getFlags() & MESSAGE_TEMP){
        if (s_tempMsg == NULL)
            s_tempMsg = new MAP_MSG;
		msg_save ms;
		ms.msg     = line;
		ms.contact = msg->contact();
		if (msg->client())
			ms.client = msg->client();
        s_tempMsg->insert(MAP_MSG::value_type(++s_tempId, ms));
        msg->setId(s_tempId);
        return;
    }
    string name = msg->client();
    if (name.empty())
        name = number(msg->contact());
    string f_name = HISTORY_PATH;
    f_name += name;

    name = user_file(f_name.c_str());
    QFile f(QString::fromUtf8(name.c_str()));
    if (!f.open(IO_ReadWrite | IO_Append)){
        log(L_ERROR, "Can't open %s", name.c_str());
        return;
    }
    unsigned id = f.at();
    f.writeBlock(line.c_str(), line.size());
    msg->setId(id);
}
Exemplo n.º 3
0
void History::add(Message *msg, const char *type)
{
    string name = msg->client();
    if (name.empty())
        name = number(msg->contact());
    string f_name = HISTORY_PATH;
    f_name += name;

    name = user_file(f_name.c_str());
    QFile f(QString::fromUtf8(name.c_str()));
    if (!f.open(IO_ReadWrite | IO_Append)){
        log(L_ERROR, "Can't open %s", name.c_str());
        return;
    }
    unsigned id = f.at();
    string line = "[";
    line += type;
    line += "]\n";
    f.writeBlock(line.c_str(), line.size());
    line = msg->save();
    if (!line.empty()){
        line += "\n";
        f.writeBlock(line.c_str(), line.size());
    }
    msg->setId(id);
}
Exemplo n.º 4
0
void HistoryConfig::viewChanged(QWidget *w)
{
    int cur = cmbStyle->currentItem();
    if (cur < 0)
        return;
    if (w == preview){
        if (!m_styles[cur].bCustom)
            return;
        if (m_bDirty){
            m_styles[cur].text = unquoteText(edtStyle->text());
            fillPreview();
        }
    }else{
        QString xsl;
        if (m_styles[cur].text.isEmpty()){
            string name = STYLES;
            name += QFile::encodeName(m_styles[cur].name);
            name += EXT;
            name = m_styles[cur].bCustom ? user_file(name.c_str()) : app_file(name.c_str());
            QFile f(QFile::decodeName(name.c_str()));
            if (f.open(IO_ReadOnly)){
                name = "";
                name.append(f.size(), '\x00');
                f.readBlock((char*)(name.c_str()), f.size());
                xsl = QString::fromUtf8(name.c_str());
            }else{
                log(L_WARN, "Can't open %s", name.c_str());
            }
        }else{
            xsl = m_styles[cur].text;
        }
        edtStyle->setText(quoteString(xsl));
        QTimer::singleShot(0, this, SLOT(sync()));
    }
}
Exemplo n.º 5
0
bool MigratePlugin::init()
{
    string path = user_file("");
    QString dir = QFile::decodeName(path.c_str());
    QDir d(dir);
    if (!d.exists())
        return false;
    QStringList cnvDirs;
    QStringList dirs = d.entryList(QDir::Dirs);
    QStringList::Iterator it;
    for (it = dirs.begin(); it != dirs.end(); ++it){
        if ((*it)[0] == '.')
            continue;
        QString p = dir + (*it);
#ifdef WIN32
        p += "\\";
#else
        p += "/";
#endif
        QFile icqConf(p + "icq.conf");
        QFile clientsConf(p + "clients.conf");
        if (icqConf.exists() && !clientsConf.exists()){
            cnvDirs.append(*it);
        }
    }
    if (cnvDirs.count() == 0)
        return false;
    MigrateDialog dlg(dir, cnvDirs);
    dlg.exec();
    return true;
}
Exemplo n.º 6
0
MessageConfig::MessageConfig(QWidget *parent, void *_data)
        : MessageConfigBase(parent)
{
    CoreUserData *data = (CoreUserData*)_data;
    chkWindow->setChecked(data->OpenOnReceive);
    chkOnline->setChecked(data->OpenOnOnline);
    chkStatus->setChecked(data->LogStatus);
    edtPath->setDirMode(true);
    QString incoming = QFile::encodeName(data->IncomingPath ? user_file(data->IncomingPath).c_str() : "");
    edtPath->setText(incoming);
    connect(grpAccept, SIGNAL(clicked(int)), this, SLOT(acceptClicked(int)));
    switch (data->AcceptMode){
	case 0:
		btnDialog->setChecked(true);
		break;
	case 1:
		btnAccept->setChecked(true);
		break;
	case 2:
		btnDecline->setChecked(true);
		break;
	}
    chkOverwrite->setChecked(data->OverwriteFiles);
    if (data->DeclineMessage)
        edtDecline->setText(QString::fromUtf8(data->DeclineMessage));
    acceptClicked(data->AcceptMode);
}
Exemplo n.º 7
0
FileConfig::FileConfig(QWidget *parent, void *_data)
        : QWidget( parent)
{
    setupUi( this);
    CoreUserData *data = (CoreUserData*)_data;
    edtPath->setDirMode(true);
    QString incoming = QFile::encodeName(data->IncomingPath.ptr ? user_file(data->IncomingPath.ptr).c_str() : "");
    edtPath->setText(incoming);
    connect(grpAccept, SIGNAL(clicked(int)), this, SLOT(acceptClicked(int)));
    switch (data->AcceptMode.value){
    case 0:
        btnDialog->setChecked(true);
        break;
    case 1:
        btnAccept->setChecked(true);
        break;
    case 2:
        btnDecline->setChecked(true);
        break;
    }
    chkOverwrite->setChecked(data->OverwriteFiles.bValue);
    if (data->DeclineMessage.ptr)
        edtDecline->setText(QString::fromUtf8(data->DeclineMessage.ptr));
    acceptClicked(data->AcceptMode.value);
}
Exemplo n.º 8
0
void HistoryConfig::realRename()
{
    QString newName = cmbStyle->lineEdit()->text();
    cmbStyle->lineEdit()->removeEventFilter(this);
    cmbStyle->setEditable(false);
    if (newName != m_styles[m_edit].name){
        int n = 0;
        vector<StyleDef>::iterator it;
        for (it = m_styles.begin(); it != m_styles.end(); ++it, n++){
            if ((*it).name == newName){
                if (n < m_edit)
                    m_edit--;
                m_styles.erase(it);
                break;
            }
        }
        string nn;
        nn = STYLES;
        nn += QFile::encodeName(m_styles[m_edit].name);
        nn += EXT;
        nn = user_file(nn.c_str());
        if (m_styles[m_edit].text.isEmpty()){
            QFile f(QFile::decodeName(nn.c_str()));
            if (f.open(IO_ReadOnly)){
                string s;
                s.append(f.size(), '\x00');
                f.readBlock((char*)(s.c_str()), f.size());
                m_styles[m_edit].text = QString::fromUtf8(s.c_str());
            }
        }
        QFile::remove(QFile::decodeName(nn.c_str()));
        m_styles[m_edit].name = newName;
    }
    fillCombo(newName);
}
Exemplo n.º 9
0
void PluginManagerPrivate::saveState()
{
    if (m_bAbort)
        return;
    getContacts()->save();
    string cfgName = user_file(PLUGINS_CONF);
    QFile f(QFile::decodeName(cfgName.c_str()));
    if (!f.open(IO_WriteOnly | IO_Truncate)){
        log(L_ERROR, "Can't create %s", cfgName.c_str());
        return;
    }
    for (unsigned i = 0; i < plugins.size(); i++){
        pluginInfo &info = plugins[i];
        string line = "[";
        line += info.name;
        line += "]\n";
        line += info.bDisabled ? DISABLE : ENABLE;
        line += ",";
        line += number(info.base);
        line += "\n";
        f.writeBlock(line.c_str(), line.length());
        if (info.plugin){
            string cfg = info.plugin->getConfig();
            if (cfg.length()){
                f.writeBlock(cfg.c_str(), cfg.length());
                f.writeBlock("\n", 1);
            }
        }
    }
}
Exemplo n.º 10
0
HistoryConfig::HistoryConfig(QWidget *parent)
        : HistoryConfigBase(parent)
{
    chkOwn->setChecked(CorePlugin::m_plugin->getOwnColors());
    chkSmile->setChecked(CorePlugin::m_plugin->getUseSmiles());
    cmbPage->setEditable(true);
    cmbPage->insertItem("100");
    cmbPage->insertItem("50");
    cmbPage->insertItem("25");
    m_cur = -1;
    QLineEdit *edit = cmbPage->lineEdit();
    edit->setValidator(new QIntValidator(1, 500, edit));
    edit->setText(QString::number(CorePlugin::m_plugin->getHistoryPage()));
    QString str1 = i18n("Show %1 messages per page");
    QString str2;
    int n = str1.find("%1");
    if (n >= 0){
        str2 = str1.mid(n + 2);
        str1 = str1.left(n);
    }
    lblPage1->setText(str1);
    lblPage2->setText(str2);
    edtStyle->setWordWrap(QTextEdit::NoWrap);
    edtStyle->setTextFormat(QTextEdit::RichText);
#if (QT_VERSION < 0x300) || ((QT_VERSION >= 0x300) && defined(HAVE_QSYNTAXHIGHLIGHTER_H))
    new XmlHighlighter(edtStyle);
#endif
    QStringList styles;
    addStyles(user_file(STYLES).c_str(), true);
#ifdef USE_KDE
    QStringList lst = KGlobal::dirs()->findDirs("data", "sim");
    for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it){
        QFile fi(*it + STYLES);
        if (!fi.exists())
            continue;
        addStyles(QFile::encodeName(fi.name()), false);
    }
#else
    addStyles(app_file(STYLES).c_str(), false);
#endif
    fillCombo(CorePlugin::m_plugin->getHistoryStyle());
    connect(cmbStyle, SIGNAL(activated(int)), this, SLOT(styleSelected(int)));
    connect(btnCopy, SIGNAL(clicked()), this, SLOT(copy()));
    connect(btnRename, SIGNAL(clicked()), this, SLOT(rename()));
    connect(btnDelete, SIGNAL(clicked()), this, SLOT(del()));
    connect(tabStyle, SIGNAL(currentChanged(QWidget*)), this, SLOT(viewChanged(QWidget*)));
    connect(edtStyle, SIGNAL(textChanged()), this, SLOT(textChanged()));
    connect(chkOwn, SIGNAL(toggled(bool)), this, SLOT(toggled(bool)));
    connect(chkSmile, SIGNAL(toggled(bool)), this, SLOT(toggled(bool)));
    connect(chkDays, SIGNAL(toggled(bool)), this, SLOT(toggledDays(bool)));
    connect(chkSize, SIGNAL(toggled(bool)), this, SLOT(toggledSize(bool)));
    HistoryUserData *data = (HistoryUserData*)(getContacts()->getUserData(CorePlugin::m_plugin->history_data_id));
    chkDays->setChecked(data->CutDays.bValue);
    chkSize->setChecked(data->CutSize.bValue);
    edtDays->setValue(data->Days.value);
    edtSize->setValue(data->MaxSize.value);
    toggledDays(chkDays->isChecked());
    toggledSize(chkSize->isChecked());
}
Exemplo n.º 11
0
void PluginManagerPrivate::loadState()
{
    if (m_bLoaded)
        return;
    m_bLoaded = true;
    string cfgName = user_file(PLUGINS_CONF);
    QFile f(QFile::decodeName(cfgName.c_str()));
    if (!f.open(IO_ReadOnly)){
        log(L_ERROR, "Can't create %s", cfgName.c_str());
        return;
    }
    unsigned i = NO_PLUGIN;
    string cfg;
    string s;
    while (getLine(f, s)){
        if (s[0] != '['){
            if (i != NO_PLUGIN){
                cfg += s;
                cfg += "\n";
            }
            continue;
        }

        if (cfg.length() && (i != NO_PLUGIN))
            plugins[i].config = strdup(cfg.c_str());
        cfg = "";
        s = s.substr(1);
        string name = getToken(s, ']');
        i = NO_PLUGIN;
        for (unsigned n = 0; n < plugins.size(); n++){
            if (!strcmp(name.c_str(), plugins[n].name)){
                i = n;
                break;
            }
        }
        if (!getLine(f, s))
            break;
        if (i == NO_PLUGIN)
            continue;
        pluginInfo &info = plugins[i];
        string token = getToken(s, ',');
        if (!strcmp(token.c_str(), ENABLE)){
            info.bDisabled = false;
            info.bFromCfg  = true;
        }else if (!strcmp(token.c_str(), DISABLE)){
            info.bDisabled = true;
            info.bFromCfg  = true;
        }else{
            continue;
        }
        token = getToken(s, ',');
        info.base = atol(token.c_str());
        if (info.base > m_base)
            m_base = info.base;
    }
    if (cfg.length() && (i != NO_PLUGIN))
        plugins[i].config = strdup(cfg.c_str());
}
Exemplo n.º 12
0
void GpgGen::genKeyReady(Exec*,int res,const char*)
{
#ifdef WIN32
    QFile::remove(QFile::decodeName(user_file("keys\\genkey.txt").c_str()));
#else
    QFile::remove(QFile::decodeName(user_file("keys/genkey.txt").c_str()));
#endif
    if (res == 0){
        GpgGenBase::accept();
        return;
    }
    edtName->setEnabled(true);
    cmbMail->setEnabled(true);
    edtComment->setEnabled(true);
    lblProcess->setText("");
    buttonOk->setEnabled(true);
    BalloonMsg::message(i18n("Generate key failed"), buttonOk);
}
Exemplo n.º 13
0
void History::remove(Contact *contact)
{
    string name = number(contact->id());
    string f_name = HISTORY_PATH;
    f_name += name;
    name = user_file(f_name.c_str());
    QFile f(QFile::decodeName(name.c_str()));
    f.remove();
    void *data;
    ClientDataIterator it(contact->clientData);
    while ((data = ++it) != NULL){
        name = it.client()->dataName(data);
        f_name = HISTORY_PATH;
        f_name += name;
        name = user_file(f_name.c_str());
        QFile f(QString::fromUtf8(name.c_str()));
        f.remove();
    }
}
Exemplo n.º 14
0
HistoryFile::HistoryFile(const char *name, unsigned contact)
{
    m_contact = contact;
    m_name = name;

    string f_name = HISTORY_PATH;
    f_name += name;

    f_name = user_file(f_name.c_str());
    setName(QString::fromUtf8(f_name.c_str()));
    open(IO_ReadOnly);
}
Exemplo n.º 15
0
/*
 * assumes that the movie offsets are already loaded
 */
void IBBL_LargeFile::build_user_binaries()
{
  cout << "Building User Binaries..." << endl;
  
  time_t start_time = time(NULL);

  const int user_batch_size = 20000;
  const int num_users = user_list.size();
  int num_full_batches = num_users / user_batch_size;
    
  int_set::iterator batch_start = user_list.begin();
  int_set::iterator batch_end = batch_start;
  batch_end += user_batch_size;

  string user_filename = get_user_binary_filename();
  string user_offset_filename = get_user_offset_filename();

  ofstream user_file(user_filename.c_str(), ofstream::binary);
  ofstream user_offset_file(user_offset_filename.c_str(), ofstream::binary);
  user_offset_file.write((char*)&num_users, 4); 

  // build the batches, one at a time 
  int offset = 0;

  for (int i = 0; i < num_full_batches; 
       ++i, batch_start = batch_end, batch_end += user_batch_size)
  {
    cout << (i + 1) << " of " << (num_full_batches + 1) << ": " << flush;
    append_user_batch(batch_start, batch_end, offset, 
                      user_offset_file, user_file);
    cout << "done." << endl;
  }

  cout << (num_full_batches + 1) << " of " << (num_full_batches + 1) 
       << ": " << flush;
  int_set::iterator end = user_list.end();
  append_user_batch(batch_start, end, offset, 
                    user_offset_file, user_file);
  cout << "done." << endl;                          

  // print the time required to do perform the operation
  time_t diff_time = time(NULL) - start_time;

  cout << "User binaries completed building in "  
       << (diff_time / 3600) << ':';
  cout.width(2);
  cout.fill('0');
  cout << (diff_time % 3600) / 60 << ':';
  cout.width(2);
  cout.fill('0');
  cout << (diff_time % 60) << endl;
  cout.width(1);
}
Exemplo n.º 16
0
void GpgPlugin::importReady(Exec *exec, int res, const char*)
{
    for (list<DecryptMsg>::iterator it = m_import.begin(); it != m_import.end(); ++it){
        if ((*it).exec == exec){
            if (res == 0){
                Message *msg = new Message(MessageGPGKey);
                QString err(exec->bErr.data());
                QRegExp r1("[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]:");
                QRegExp r2("\".*\"");
                int len;
                int pos = r1.match(err, 0, &len);
                if (pos >= 0){
                    QString key_name;
                    key_name  = err.mid(pos + 1, len - 2);
                    QString text = key_name;
                    text += " ";
                    pos = r2.match(err, 0, &len);
                    text += err.mid(pos + 1, len - 2);
                    msg->setText(text);
                    msg->setContact((*it).msg->contact());
                    msg->setClient((*it).msg->client());
                    msg->setFlags((*it).msg->getFlags());
                    delete (*it).msg;
                    (*it).msg = msg;

                    QString home = QFile::decodeName(user_file(GpgPlugin::plugin->getHome()).c_str());
                    if (home[(int)(home.length() - 1)] == '\\')
                        home = home.left(home.length() - 1);
                    QString gpg;
                    gpg += "\"";
                    gpg += QFile::decodeName(GPG());
                    gpg += "\" --homedir \"";
                    gpg += home;
                    gpg += "\" ";
                    gpg += getPublicList();
                    DecryptMsg dm;
                    dm.exec    = new Exec;
                    dm.contact = msg->contact();
                    dm.outfile = key_name;
                    m_public.push_back(dm);
                    connect(dm.exec, SIGNAL(ready(Exec*,int,const char*)), this, SLOT(publicReady(Exec*,int,const char*)));
                    dm.exec->execute(gpg.local8Bit(), "\n");
                }
            }
            Event e(EventMessageReceived, (*it).msg);
            if (!e.process(this))
                delete (*it).msg;
            (*it).msg = NULL;
            QFile::remove((*it).infile);
            QTimer::singleShot(0, this, SLOT(clear()));
            return;
        }
Exemplo n.º 17
0
// static
void LLSpellChecker::refreshDictionaryMap()
{
	const std::string app_path = getDictionaryAppPath();
	const std::string user_path = getDictionaryUserPath();

	// Load dictionary information (file name, friendly name, ...)
    std::string user_filename(user_path + DICT_FILE_MAIN);
	llifstream user_file(user_filename.c_str(), std::ios::binary);
	if ( (!user_file.is_open()) 
		|| (LLSDParser::PARSE_FAILURE == LLSDSerialize::fromXMLDocument(sDictMap, user_file)) 
		|| (0 == sDictMap.size()) )
	{
        std::string app_filename(app_path + DICT_FILE_MAIN);
		llifstream app_file(app_filename.c_str(), std::ios::binary);
		if ( (!app_file.is_open()) 
			|| (LLSDParser::PARSE_FAILURE == LLSDSerialize::fromXMLDocument(sDictMap, app_file)) 
			|| (0 == sDictMap.size()) )
		{
			return;
		}
	}

	// Load user installed dictionary information
	llifstream custom_file(user_filename.c_str(), std::ios::binary);
	if (custom_file.is_open())
	{
		LLSD custom_dict_map;
		LLSDSerialize::fromXMLDocument(custom_dict_map, custom_file);
		for (LLSD::array_iterator it = custom_dict_map.beginArray(); it != custom_dict_map.endArray(); ++it)
		{
			LLSD& dict_info = *it;
			dict_info["user_installed"] = true;
			setDictionaryData(dict_info);
		}
		custom_file.close();
	}

	// Look for installed dictionaries
	std::string tmp_app_path, tmp_user_path;
	for (LLSD::array_iterator it = sDictMap.beginArray(); it != sDictMap.endArray(); ++it)
	{
		LLSD& sdDict = *it;
		tmp_app_path = (sdDict.has("name")) ? app_path + sdDict["name"].asString() : LLStringUtil::null;
		tmp_user_path = (sdDict.has("name")) ? user_path + sdDict["name"].asString() : LLStringUtil::null;
		sdDict["installed"] = 
			(!tmp_app_path.empty()) && ((gDirUtilp->fileExists(tmp_user_path + ".dic")) || (gDirUtilp->fileExists(tmp_app_path + ".dic")));
	}

	sSettingsChangeSignal();
}
Exemplo n.º 18
0
void HistoryConfig::apply()
{
    bool bChanged = false;
    for (unsigned i = 0; i < m_styles.size(); i++){
        if (m_styles[i].text.isEmpty() || !m_styles[i].bCustom)
            continue;
        if ((int)i == cmbStyle->currentItem())
            bChanged = true;
        string name = STYLES;
        name += QFile::encodeName(m_styles[i].name);
        name += EXT;
        name = user_file(name.c_str());
        QFile f(QFile::decodeName(name.c_str()));
        if (f.open(IO_WriteOnly | IO_Truncate)){
            string s;
            s = m_styles[i].text.utf8();
            f.writeBlock(s.c_str(), s.length());
        }else{
            log(L_WARN, "Can't create %s", name.c_str());
        }
    }
    int cur = cmbStyle->currentItem();
    if ((cur >= 0) && (m_styles[cur].name != QFile::decodeName(CorePlugin::m_plugin->getHistoryStyle()))){
        CorePlugin::m_plugin->setHistoryStyle(QFile::encodeName(m_styles[cur].name));
        bChanged = true;
    }
    delete CorePlugin::m_plugin->historyXSL;
    CorePlugin::m_plugin->historyXSL = new XSL(m_styles[cur].name);

    if (chkOwn->isChecked() != CorePlugin::m_plugin->getOwnColors()){
        bChanged = true;
        CorePlugin::m_plugin->setOwnColors(chkOwn->isChecked());
    }
    if (chkSmile->isChecked() != CorePlugin::m_plugin->getUseSmiles()){
        bChanged = true;
        CorePlugin::m_plugin->setUseSmiles(chkSmile->isChecked());
    }
    CorePlugin::m_plugin->setHistoryPage(atol(cmbPage->lineEdit()->text().latin1()));
    if (bChanged){
        Event e(EventHistoryConfig);
        e.process();
        fillPreview();
    }
    HistoryUserData *data = (HistoryUserData*)(getContacts()->getUserData(CorePlugin::m_plugin->history_data_id));
	data->CutDays = chkDays->isChecked();
	data->CutSize = chkSize->isChecked();
	data->Days    = atol(edtDays->text());
	data->MaxSize = atol(edtSize->text());
}
Exemplo n.º 19
0
void LoginDialog::profileDelete()
{
    int n = cmbProfile->currentItem();
    if ((n < 0) || (n >= (int)(CorePlugin::m_plugin->m_profiles.size())))
        return;
    string curProfile = CorePlugin::m_plugin->m_profiles[n];
    CorePlugin::m_plugin->setProfile(curProfile.c_str());
    rmDir(QFile::decodeName(user_file("").c_str()));
    CorePlugin::m_plugin->setProfile(NULL);
    CorePlugin::m_plugin->changeProfile();
    CorePlugin::m_plugin->m_profiles.clear();
    CorePlugin::m_plugin->loadDir();
    clearInputs();
    btnDelete->setEnabled(false);
    fill();
}
Exemplo n.º 20
0
HistoryConfig::HistoryConfig(QWidget *parent)
        : HistoryConfigBase(parent)
{
    chkOwn->setChecked(CorePlugin::m_plugin->getOwnColors());
    chkSmile->setChecked(CorePlugin::m_plugin->getUseSmiles());
    cmbPage->setEditable(true);
    cmbPage->insertItem("100");
    cmbPage->insertItem("50");
    cmbPage->insertItem("25");
    m_cur = -1;
    QLineEdit *edit = cmbPage->lineEdit();
    edit->setValidator(new QIntValidator(1, 500, edit));
    edit->setText(QString::number(CorePlugin::m_plugin->getHistoryPage()));
    QString str1 = i18n("Show %1 messages per page");
    QString str2;
    int n = str1.find("%1");
    if (n >= 0){
        str2 = str1.mid(n + 2);
        str1 = str1.left(n);
    }
    lblPage1->setText(str1);
    lblPage2->setText(str2);
    edtStyle->setWordWrap(QTextEdit::NoWrap);
    edtStyle->setTextFormat(QTextEdit::RichText);
    new XmlHighlighter(edtStyle);
    QStringList styles;
    addStyles(user_file(STYLES).c_str(), true);
    addStyles(app_file(STYLES).c_str(), false);
    fillCombo(CorePlugin::m_plugin->getHistoryStyle());
    connect(cmbStyle, SIGNAL(activated(int)), this, SLOT(styleSelected(int)));
    connect(btnCopy, SIGNAL(clicked()), this, SLOT(copy()));
    connect(btnRename, SIGNAL(clicked()), this, SLOT(rename()));
    connect(btnDelete, SIGNAL(clicked()), this, SLOT(del()));
    connect(tabStyle, SIGNAL(currentChanged(QWidget*)), this, SLOT(viewChanged(QWidget*)));
    connect(edtStyle, SIGNAL(textChanged()), this, SLOT(textChanged()));
    connect(chkOwn, SIGNAL(toggled(bool)), this, SLOT(toggled(bool)));
    connect(chkSmile, SIGNAL(toggled(bool)), this, SLOT(toggled(bool)));
    connect(chkDays, SIGNAL(toggled(bool)), this, SLOT(toggledDays(bool)));
    connect(chkSize, SIGNAL(toggled(bool)), this, SLOT(toggledSize(bool)));
    HistoryUserData *data = (HistoryUserData*)(getContacts()->getUserData(CorePlugin::m_plugin->history_data_id));
    chkDays->setChecked(data->CutDays != 0);
    chkSize->setChecked(data->CutSize != 0);
    edtDays->setValue(data->Days);
    edtSize->setValue(data->MaxSize);
    toggledDays(chkDays->isChecked());
    toggledSize(chkSize->isChecked());
}
Exemplo n.º 21
0
void MigrateDialog::pageSelected(const QString&)
{
    if (currentPage() != page2)
        return;
    backButton()->hide();
    setFinishEnabled(page2, false);
    list<QCheckBox*>::iterator it;
    for (it = m_boxes.begin(); it != m_boxes.end(); ++it){
        if ((*it)->isChecked()){
            m_bProcess = true;
            break;
        }
    }
    if (!m_bProcess){
        reject();
        return;
    }
    unsigned totalSize = 0;
    for (it = m_boxes.begin(); it != m_boxes.end(); ++it){
        if (!(*it)->isChecked())
            continue;
        QString path = QFile::decodeName(user_file(QFile::encodeName((*it)->text())).c_str());
#ifdef WIN32
        path += "\\";
#else
        path += "/";
#endif
        QFile icq_conf(path + "icq.conf");
        totalSize += icq_conf.size();
        QString history_path = path + "history";
#ifdef WIN32
        history_path += "\\";
#else
        history_path += "/";
#endif
        QDir history(history_path);
        QStringList l = history.entryList("*.history", QDir::Files);
        for (QStringList::Iterator it = l.begin(); it != l.end(); ++it){
            QFile hf(history_path + (*it));
            totalSize += hf.size();
        }
    }
    barCnv->setTotalSteps(totalSize);
    QTimer::singleShot(0, this, SLOT(process()));
}
Exemplo n.º 22
0
SmileCfg::SmileCfg(QWidget *parent, IconsPlugin *plugin)
        : SmileCfgBase(parent)
{
    m_plugin = plugin;
    lblMore->setUrl("http://miranda-im.org/download/index.php?action=display&id=41");
#ifdef WIN32
    edtSmiles->setStartDir(QFile::decodeName(app_file("smiles/").c_str()));
#else
    edtSmiles->setStartDir(QFile::decodeName(user_file("smiles/").c_str()));
#endif
    edtSmiles->setTitle(i18n("Select smiles"));
    edtSmiles->setFilePreview(createPreview);
#ifdef USE_KDE
    edtSmiles->setFilter(i18n("*.msl *.xep|Smiles"));
#else
    edtSmiles->setFilter(i18n("Smiles (*.msl *.xep)"));
#endif
    edtSmiles->setText(m_plugin->getSmiles());
    lblMore->setText(i18n("Get more smiles"));
}
Exemplo n.º 23
0
void HistoryConfig::realDelete()
{
	int cur = cmbStyle->currentItem();
	if (cur < 0)
		return;
	if (!m_styles[cur].bCustom)
		return;
	QString name = m_styles[cur].name;
	for (vector<StyleDef>::iterator it = m_styles.begin(); it != m_styles.end(); ++it)
		if (cur-- == 0)
			break;
	m_styles.erase(it);
	string n;
	n = STYLES;
	n += QFile::encodeName(name);
	n += EXT;
	n = user_file(n.c_str());
	QFile::remove(QFile::decodeName(n.c_str()));
	fillCombo(CorePlugin::m_plugin->getHistoryStyle());
}
Exemplo n.º 24
0
void FileConfig::apply(void *_data)
{
    CoreUserData *data = (CoreUserData*)_data;
    QString def;
    if (edtPath->text().isEmpty()) {
        def = "Incoming Files";
    } else {
        def = edtPath->text();
    }
    set_str(&data->IncomingPath.ptr, QFile::encodeName(def));
    edtPath->setText(QFile::decodeName(data->IncomingPath.ptr ? user_file(data->IncomingPath.ptr).c_str() : ""));
    data->AcceptMode.value = 0;
    if (btnAccept->isOn()){
        data->AcceptMode.value = 1;
        data->OverwriteFiles.bValue = chkOverwrite->isChecked();
    }
    if (btnDecline->isOn()){
        data->AcceptMode.value = 2;
        set_str(&data->DeclineMessage.ptr, edtDecline->text().utf8());
    }
}
Exemplo n.º 25
0
XSL::XSL(const QString &name)
{
    string fname = STYLES;
    fname += static_cast<string>(QFile::encodeName(name));
    fname += EXT;
    QFile f(QFile::decodeName(user_file(fname.c_str()).c_str()));
    bool bOK = true;
    if (!f.open(QIODevice::ReadOnly)){
        f.setFileName(QFile::decodeName(app_file(fname.c_str()).c_str()));
        if (!f.open(QIODevice::ReadOnly)){
            log(L_WARN, "Can't open %s", fname.c_str());
            bOK = false;
        }
    }
    string xsl;
    if (bOK){
        xsl.append(f.size(), '\x00');
        f.read((char*)(xsl.c_str()), f.size());
        f.close();
    }
    d = new XSLPrivate(xsl.c_str());
}
Exemplo n.º 26
0
void MessageConfig::apply(void *_data)
{
    CoreUserData *data = (CoreUserData*)_data;
    data->OpenOnReceive = chkWindow->isChecked();
    data->OpenOnOnline  = chkWindow->isChecked();
    data->LogStatus     = chkStatus->isChecked();
    QString def;
    if (edtPath->text().isEmpty()) {
        def = "Incoming Files";
    } else {
        def = edtPath->text();
    }
    set_str(&data->IncomingPath, QFile::encodeName(def));
    edtPath->setText(QFile::decodeName(data->IncomingPath ? user_file(data->IncomingPath).c_str() : ""));
    data->AcceptMode = 0;
    if (btnAccept->isOn()){
		data->AcceptMode = 1;
        data->OverwriteFiles = chkOverwrite->isChecked();
	}
    if (btnDecline->isOn()){
		data->AcceptMode = 2;
        set_str(&data->DeclineMessage, edtDecline->text().utf8());
	}
}
Exemplo n.º 27
0
GpgCfg::GpgCfg(QWidget *parent, GpgPlugin *plugin)
        : GpgCfgBase(parent)
{
    m_plugin = plugin;
    m_exec   = NULL;
    m_bNew   = false;
#ifdef WIN32
    edtGPG->setText(QFile::decodeName(m_plugin->getGPG()));
    edtGPG->setFilter(i18n("GPG(gpg.exe)"));
    m_find = NULL;
#else
    lblGPG->hide();
    edtGPG->hide();
#endif
    edtHome->setText(QFile::decodeName(user_file(m_plugin->getHome()).c_str()));
    edtHome->setDirMode(true);
    edtHome->setTitle(i18n("Select home directory"));
    lnkGPG->setUrl("http://www.gnupg.org/(en)/download/index.html");
    lnkGPG->setText(i18n("Download GPG"));
    connect(btnFind, SIGNAL(clicked()), this, SLOT(find()));
    connect(edtGPG, SIGNAL(textChanged(const QString&)), this, SLOT(textChanged(const QString&)));
    textChanged(edtGPG->text());
    for (QObject *p = parent; p != NULL; p = p->parent()){
        if (!p->inherits("QTabWidget"))
            continue;
        QTabWidget *tab = static_cast<QTabWidget*>(p);
        m_adv = new GpgAdvanced(tab, plugin);
        tab->addTab(m_adv, i18n("&Advanced"));
        tab->adjustSize();
        break;
    }
    connect(btnRefresh, SIGNAL(clicked()), this, SLOT(refresh()));
    connect(cmbKey, SIGNAL(activated(int)), this, SLOT(selectKey(int)));
    fillSecret(NULL);
    refresh();
}
Exemplo n.º 28
0
void MigrateDialog::process()
{
    unsigned size = 0;
    for (list<QCheckBox*>::iterator it = m_boxes.begin(); it != m_boxes.end(); ++it){
        if (!(*it)->isChecked())
            continue;
        QString path = QFile::decodeName(user_file(QFile::encodeName((*it)->text())).c_str());
#ifdef WIN32
        path += "\\";
#else
        path += "/";
#endif
        icqConf.close();
        clientsConf.close();
        contactsConf.close();
        icqConf.setName(path + "icq.conf");
        clientsConf.setName(path + "clients.conf");
        contactsConf.setName(path + "contacts.conf");
        lblStatus->setText(path + "icq.conf");
        if (!icqConf.open(IO_ReadOnly)){
            error(i18n("Can't open %1") .arg(path + "icq.conf"));
            return;
        }
        if (!clientsConf.open(IO_WriteOnly | IO_Truncate)){
            error(i18n("Can't open %1") .arg(path + "clients.conf"));
            return;
        }
        if (!contactsConf.open(IO_WriteOnly | IO_Truncate)){
            error(i18n("Can't open %1") .arg(path + "contacts.conf"));
            return;
        }
        m_uin    = 0;
        m_passwd = "";
        m_state  = 0;
        m_grpId		= 0;
        m_contactId = 0;
        Buffer cfg;
        cfg.init(icqConf.size());
        icqConf.readBlock(cfg.data(), icqConf.size());
        for (;;){
            string section = cfg.getSection();
            if (section.empty())
                break;
            m_state = 3;
            if (section == "Group")
                m_state = 1;
            if (section == "User")
                m_state = 2;
            if (!m_bProcess)
                return;
            for (;;){
                char *l = cfg.getLine();
                if (l == NULL)
                    break;
                string line = l;
                string name = getToken(line, '=');
                if (name == "UIN")
                    m_uin = atol(line.c_str());
                if (name == "EncryptPassword")
                    m_passwd = line;
                if (name == "Name")
                    m_name = line;
                if (name == "Alias")
                    m_name = line;
            }
            flush();
            barCnv->setProgress(cfg.readPos());
            qApp->processEvents();
        }
        icqConf.close();
        clientsConf.close();
        contactsConf.close();
        m_state = 3;
        size += icqConf.size();
        if (!m_bProcess)
            return;
        barCnv->setProgress(size);
        qApp->processEvents();
        QString h_path = path;
#ifdef WIN32
        h_path += "history\\";
#else
        h_path += "history/";
#endif
        QDir history(h_path);
        QStringList l = history.entryList("*.history", QDir::Files);
        for (QStringList::Iterator it = l.begin(); it != l.end(); ++it){
            hFrom.close();
            hTo.close();
            hFrom.setName(h_path + (*it));
            lblStatus->setText(h_path + (*it));
            hTo.setName(h_path + m_owner.c_str() + "." + (*it).left((*it).find(".")));
            if (!hFrom.open(IO_ReadOnly)){
                error(i18n("Can't open %1") .arg(hFrom.name()));
                return;
            }
            if (!hTo.open(IO_WriteOnly | IO_Truncate)){
                error(i18n("Can't open %1") .arg(hTo.name()));
                return;
            }
            cfg.init(hFrom.size());
            hFrom.readBlock(cfg.data(), hFrom.size());
            for (;;){
                string section = cfg.getSection();
                if (section.empty())
                    break;
                m_state = 3;
                if (section == "Message")
                    m_state = 4;
                if (!m_bProcess)
                    return;
                for (;;){
                    char *l = cfg.getLine();
                    if (l == NULL)
                        break;
                    string line = l;
                    string name = getToken(line, '=');
                    if (name == "Message")
                        m_message = line;
                    if (name == "Time")
                        m_time = line;
                    if (name == "Direction")
                        m_direction = line;
                    if (name == "Charset")
                        m_charset = line;
                }
                flush();
                barCnv->setProgress(cfg.readPos());
                qApp->processEvents();
            }
            hFrom.close();
            hTo.close();
            m_state = 3;
            size += hFrom.size();
            if (!m_bProcess)
                return;
            barCnv->setProgress(size);
            qApp->processEvents();
        }
        if (chkRemove->isChecked()){
            icqConf.remove();
            icqConf.setName(path + "sim.conf");
            icqConf.remove();
            for (QStringList::Iterator it = l.begin(); it != l.end(); ++it){
                hFrom.setName(h_path + (*it));
                hFrom.remove();
            }
        }
    }
    m_bProcess = false;
    accept();
}
Exemplo n.º 29
0
void HistoryConfig::copy()
{
    int cur = cmbStyle->currentItem();
    if (cur < 0)
        return;
    QString name    = m_styles[cur].name;
    QString newName;
    QRegExp re("\\.[0-9]+$");
    unsigned next = 0;
    for (vector<StyleDef>::iterator it = m_styles.begin(); it != m_styles.end(); ++it){
        QString nn = (*it).name;
        int n = nn.find(re);
        if (n < 0)
            continue;
        nn = nn.mid(n + 1);
        next = QMAX(next, nn.toUInt());
    }
    int nn = name.find(re);
    if (nn >= 0){
        newName = name.left(nn);
    }else{
        newName = name;
    }
    newName += ".";
    newName += QString::number(next + 1);
    string n;
    n = STYLES;
    n += QFile::encodeName(name);
    n += EXT;
    if (m_styles[cur].bCustom){
        n = user_file(n.c_str());
    }else{
        n = app_file(n.c_str());
    }
    QFile from(QFile::decodeName(n.c_str()));
    if (!from.open(IO_ReadOnly)){
        log(L_WARN, "Can't open %s", n.c_str());
        return;
    }
    n = STYLES;
    n += QFile::encodeName(newName);
    n += EXT;
    n = user_file(n.c_str());
    QFile to(QFile::decodeName((n + BACKUP_SUFFIX).c_str()));
    if (!to.open(IO_WriteOnly | IO_Truncate)){
        log(L_WARN, "Cam't create %s", n.c_str());
        return;
    }
    string s;
    s.append(from.size(), '\x00');
    from.readBlock((char*)(s.c_str()), from.size());
    to.writeBlock(s.c_str(), s.length());
    from.close();

    const int status = to.status();
#if QT_VERSION >= 0x030200
    const QString errorMessage = to.errorString();
#else
    const QString errorMessage = "write file fail";
#endif
    to.close();
    if (status != IO_Ok) {
        log(L_ERROR, "IO error during writting to file %s : %s", (const char*)to.name().local8Bit(), (const char*)errorMessage.local8Bit());
        return;
    }

    // rename to normal file
    QFileInfo fileInfo(to.name());
    QString desiredFileName = QFile::decodeName(n.c_str());
    if (!fileInfo.dir().rename(fileInfo.fileName(), desiredFileName)) {
        log(L_ERROR, "Can't rename file %s to %s", (const char*)fileInfo.fileName().local8Bit(), (const char*)desiredFileName.local8Bit());
        return;
    }

    s = "";
    StyleDef d;
    d.name    = newName;
    d.bCustom = true;
    m_styles.push_back(d);
    fillCombo(QFile::encodeName(newName));
}
Exemplo n.º 30
0
void HistoryConfig::apply()
{
    bool bChanged = false;
    for (unsigned i = 0; i < m_styles.size(); i++){
        if (m_styles[i].text.isEmpty() || !m_styles[i].bCustom)
            continue;
        if ((int)i == cmbStyle->currentItem())
            bChanged = true;
        string name = STYLES;
        name += QFile::encodeName(m_styles[i].name);
        name += EXT;
        name = user_file(name.c_str());
        QFile f(QFile::decodeName((name + BACKUP_SUFFIX).c_str())); // use backup file for this ...
        if (f.open(IO_WriteOnly | IO_Truncate)){
            string s;
            s = m_styles[i].text.utf8();
            f.writeBlock(s.c_str(), s.length());

            const int status = f.status();
#if QT_VERSION >= 0x030200
            const QString errorMessage = f.errorString();
#else
	    const QString errorMessage = "write file fail";
#endif
            f.close();
            if (status != IO_Ok) {
                log(L_ERROR, "IO error during writting to file %s : %s", (const char*)f.name().local8Bit(), (const char*)errorMessage.local8Bit());
            } else {
                // rename to normal file
                QFileInfo fileInfo(f.name());
                QString desiredFileName = QFile::decodeName(name.c_str());
                if (!fileInfo.dir().rename(fileInfo.fileName(), desiredFileName)) {
                    log(L_ERROR, "Can't rename file %s to %s", (const char*)fileInfo.fileName().local8Bit(), (const char*)desiredFileName.local8Bit());
                }
            }
        }else{
            log(L_WARN, "Can't create %s", name.c_str());
        }
    }
    int cur = cmbStyle->currentItem();
    if ((cur >= 0) && (m_styles[cur].name != QFile::decodeName(CorePlugin::m_plugin->getHistoryStyle()))){
        CorePlugin::m_plugin->setHistoryStyle(QFile::encodeName(m_styles[cur].name));
        bChanged = true;
    }
    delete CorePlugin::m_plugin->historyXSL;
    CorePlugin::m_plugin->historyXSL = new XSL(m_styles[cur].name);

    if (chkOwn->isChecked() != CorePlugin::m_plugin->getOwnColors()){
        bChanged = true;
        CorePlugin::m_plugin->setOwnColors(chkOwn->isChecked());
    }
    if (chkSmile->isChecked() != CorePlugin::m_plugin->getUseSmiles()){
        bChanged = true;
        CorePlugin::m_plugin->setUseSmiles(chkSmile->isChecked());
    }
    CorePlugin::m_plugin->setHistoryPage(atol(cmbPage->lineEdit()->text().latin1()));
    if (bChanged){
        Event e(EventHistoryConfig);
        e.process();
        fillPreview();
    }
    HistoryUserData *data = (HistoryUserData*)(getContacts()->getUserData(CorePlugin::m_plugin->history_data_id));
    data->CutDays = chkDays->isChecked();
    data->CutSize = chkSize->isChecked();
    data->Days    = atol(edtDays->text());
    data->MaxSize = atol(edtSize->text());
}