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 = user_file((*it)->text()); path += '/'; icqConf.close(); clientsConf.close(); contactsConf.close(); icqConf.setFileName(path + "icq.conf"); clientsConf.setFileName(path + "clients.conf"); contactsConf.setFileName(path + "contacts.conf"); lblStatus->setText(path + "icq.conf"); if (!icqConf.open(QIODevice::ReadOnly)){ error(i18n("Can't open %1") .arg(path + "icq.conf")); return; } if (!clientsConf.open(QIODevice::WriteOnly | QIODevice::Truncate)){ error(i18n("Can't open %1") .arg(path + "clients.conf")); return; } if (!contactsConf.open(QIODevice::WriteOnly | QIODevice::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.read(cfg.data(), icqConf.size()); for (;;){ QByteArray section = cfg.getSection(); if (section.isEmpty()) break; m_state = 3; if (section == "Group") m_state = 1; if (section == "User") m_state = 2; if (!m_bProcess) return; for (;;){ QByteArray l = cfg.getLine(); if (l.isEmpty()) break; QByteArray line = l; QByteArray name = getToken(line, '='); if (name == "UIN") m_uin = line.toUInt(); if (name == "EncryptPassword") m_passwd = line; if (name == "Name") m_name = line; if (name == "Alias") m_name = line; } flush(); barCnv->setValue(cfg.readPos()); qApp->processEvents(); } icqConf.close(); clientsConf.close(); contactsConf.close(); m_state = 3; size += icqConf.size(); if (!m_bProcess) return; barCnv->setValue(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(QStringList("*.history"), QDir::Files); for (QStringList::Iterator it = l.begin(); it != l.end(); ++it){ hFrom.close(); hTo.close(); hFrom.setFileName(h_path + (*it)); lblStatus->setText(h_path + (*it)); hTo.setFileName(h_path + QString(m_owner) + '.' + it->left(it->indexOf('.'))); if (!hFrom.open(QIODevice::ReadOnly)){ error(i18n("Can't open %1") .arg(hFrom.fileName())); return; } if (!hTo.open(QIODevice::WriteOnly | QIODevice::Truncate)){ error(i18n("Can't open %1") .arg(hTo.fileName())); return; } cfg.init(hFrom.size()); hFrom.read(cfg.data(), hFrom.size()); for (;;){ QByteArray section = cfg.getSection(); if (section.isEmpty()) break; m_state = 3; if (section == "Message") m_state = 4; if (!m_bProcess) return; for (;;){ QByteArray l = cfg.getLine(); if (l.isEmpty()) break; QByteArray line = l; QByteArray 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->setValue(cfg.readPos()); qApp->processEvents(); } hFrom.close(); hTo.close(); m_state = 3; size += hFrom.size(); if (!m_bProcess) return; barCnv->setValue(size); qApp->processEvents(); } if (chkRemove->isChecked()){ icqConf.remove(); icqConf.setFileName(path + "sim.conf"); icqConf.remove(); for (QStringList::Iterator it = l.begin(); it != l.end(); ++it){ hFrom.setFileName(h_path + (*it)); hFrom.remove(); } } } m_bProcess = false; accept(); }
bool QOptions::parse(int argc, const char *const*argv) { if (mOptionGroupMap.isEmpty()) return false; if (argc==1) return true; bool result = true; QStringList args; for (int i=1;i<argc;++i) { args.append(QString::fromLocal8Bit(argv[i])); } QStringList::Iterator it = args.begin(); QList<QOption>::Iterator it_list; mOptions = mOptionGroupMap.keys(); while (it != args.end()) { if (it->startsWith("--")) { int e = it->indexOf('='); for (it_list = mOptions.begin(); it_list != mOptions.end(); ++it_list) { if (it_list->longName() == it->mid(2,e-2)) { if (it_list->type()==QOption::NoToken) { it_list->setValue(true); //qDebug("%d %s", __LINE__, qPrintable(it_list->value().toString())); it = args.erase(it); break; } if (e>0) { // it_list->setValue(it->mid(e+1)); //qDebug("%d %s", __LINE__, qPrintable(it_list->value().toString())); } else { it = args.erase(it); if (it == args.end()) break; it_list->setValue(*it); //qDebug("%d %s", __LINE__, qPrintable(it_list->value().toString())); } it = args.erase(it); break; } } if (it_list == mOptions.end()) { qWarning() << "unknow option: " << *it; result = false; ++it; } //handle unknow option } else if (it->startsWith('-')) { for (it_list = mOptions.begin(); it_list != mOptions.end(); ++it_list) { QString sname = it_list->shortName(); int sname_len = sname.length(); //usally is 1 //TODO: startsWith(-height,-h) Not endsWith, -oabco if (it->midRef(1).compare(sname) == 0) { if (it_list->type() == QOption::NoToken) { it_list->setValue(true); it = args.erase(it); break; } if (it->length() == sname_len+1) {//-o abco it = args.erase(it); if (it == args.end()) break; it_list->setValue(*it); //qDebug("%d %s", __LINE__, qPrintable(it_list->value().toString())); } else { it_list->setValue(it->mid(sname_len+1)); //qDebug("%d %s", __LINE__, qPrintable(it_list->value().toString())); } it = args.erase(it); break; } } if (it_list==mOptions.end()) { qWarning() << "unknow option: " << *it; result = false; ++it; } //handle unknow option } else { qWarning() << "unknow option: " << *it; ++it; } } if (!result) { print(); } return result; }