ProfileCreationWizard::ProfileCreationWizard(ModuleManager *parent, const QString &id, const QString &password, bool singleProfile) { m_manager = parent; m_singleProfile = singleProfile; QDir tmpDir = QDir::temp(); QString path; do { path = "qutim-" + randomString(6) + "-profile"; } while (tmpDir.exists(path)); if (!tmpDir.mkpath(path) || !tmpDir.cd(path)) { qFatal("Can't access or create directory: \"%s\"", qPrintable(tmpDir.absoluteFilePath(path))); } QVector<QDir> &systemDirs = *system_info_dirs(); systemDirs[SystemInfo::ConfigDir] = tmpDir.absoluteFilePath("config"); systemDirs[SystemInfo::HistoryDir] = tmpDir.absoluteFilePath("history"); systemDirs[SystemInfo::ShareDir] = tmpDir.absoluteFilePath("share"); for (int i = SystemInfo::ConfigDir; i <= SystemInfo::ShareDir; i++) tmpDir.mkdir(systemDirs[i].dirName()); qDebug() << Q_FUNC_INFO << SystemInfo::getPath(SystemInfo::ConfigDir); setProperty("singleProfile",singleProfile); setProperty("password",password); addPage(new ProfileCreationPage(this)); QString realId; QString realName; if (id.isEmpty()) { #if defined(Q_OS_UNIX) QT_TRY { struct passwd *userInfo = getpwuid(getuid()); QTextCodec *codec = QTextCodec::codecForLocale(); realId = codec->toUnicode(userInfo->pw_name); realName = codec->toUnicode(userInfo->pw_gecos).section(',', 0, 0); } QT_CATCH(...) { } #elif defined(Q_OS_WIN32) // TCHAR wTId[UNLEN + 1]; // DWORD wSId = sizeof(wTId); // if (GetUserName(wTId, &wSId)) // #if defined(UNICODE) // realid= QString::fromUtf16((ushort*)wTId); // #else // realId = QString::fromLocal8Bit(wTId); // #endif // TCHAR wTName[1024]; // DWORD wSName = 1024; // if (GetUserNameEx(NameDisplay, wTName, &wSName)) // #if defined( UNICODE ) // realName = QString::fromUtf16((ushort*)wTName); // #else // realName = QString::fromLocal8Bit(wTName); // #endif #endif if (realName.isEmpty()) realName = realId; } else {
ModuleManagerImpl::ModuleManagerImpl() { ModuleManager::loadPlugins(); CryptoService *cryptoService = NULL; foreach (const ObjectGenerator *gen, ObjectGenerator::module<CryptoService>()) { if (CRYPTO_BACKEND == QLatin1String(gen->metaObject()->className())) { cryptoService = gen->generate<CryptoService>(); break; } } QList<ConfigBackend*> &configBackends = get_config_backends(); foreach (const ObjectGenerator *gen, ObjectGenerator::module<ConfigBackend>()) { const ExtensionInfo info = gen->info(); ConfigBackend *backend = info.generator()->generate<ConfigBackend>(); if (QLatin1String(backend->metaObject()->className()) == CONFIG_BACKEND) configBackends.prepend(backend); else configBackends.append(backend); } Q_ASSERT(cryptoService); Q_ASSERT(!configBackends.isEmpty()); QVector<QDir> &dirs = *system_info_dirs(); dirs[SystemInfo::ConfigDir] = QDir::home().absoluteFilePath(".config/qutim"); dirs[SystemInfo::HistoryDir] = QDir::home().absoluteFilePath(".config/qutim/history"); dirs[SystemInfo::ShareDir] = QDesktopServices::storageLocation(QDesktopServices::DataLocation); Config config = Profile::instance()->config(); if (!config.hasChildGroup("profile")) { QString user; QT_TRY { struct passwd *userInfo = getpwuid(getuid()); QTextCodec *codec = QTextCodec::codecForLocale(); user = codec->toUnicode(userInfo->pw_name); } QT_CATCH(...) { } config.beginGroup("profile"); config.setValue("name", user); config.setValue("id", user); config.setValue("crypto",cryptoService->metaObject()->className()); config.setValue("config", QLatin1String(configBackends.first()->metaObject()->className())); config.setValue("portable", false); config.setValue("configDir", SystemInfo::getPath(SystemInfo::ConfigDir)); config.setValue("historyDir", SystemInfo::getPath(SystemInfo::HistoryDir)); config.setValue("shareDir", SystemInfo::getPath(SystemInfo::ShareDir)); config.endGroup(); }