Exemple #1
0
void Project::load()
{
    QDir storageLocation(PeceraApplication::instance()->getProjectStorageLocation());
    if (!storageLocation.exists())
        return;

    QFile projectFile(storageLocation.filePath(m_name + ".db"));
    if (!projectFile.exists())
        return;

    // FIXME: Better error reporting
    // From: http://www.sqlite.org/c3ref/open.html -- The encoding used for
    // the filename argument of sqlite3_open() and  sqlite3_open_v2() must be
    // UTF-8, not whatever codepage is currently defined.
    sqlite3* database;
    int rc = sqlite3_open(projectFile.fileName().toUtf8().data(), &database);
    if (rc) {
        reportError(sqlite3_errmsg(database));
        sqlite3_close(database);
        return;
    }

    char* errorMessage;
    rc = sqlite3_exec(database, "SELECT * from files", fileReadFromStorageCallback, this, &errorMessage);
    if (rc)
        sqlite3_free(errorMessage);

    sqlite3_close(database);
}
Exemple #2
0
QString LibraryInfo::logPath()
{
#if defined(Q_WS_QWS)
    return QString("/tmp");
#else
    return storageLocation(QDesktopServices::TempLocation);
#endif	//#if defined(Q_WS_QWS)
}
QString QDesktopServices::displayName(StandardLocation type)
{
    static LocalizerFunc ptrLocalizerFunc = NULL;

    if (!ptrLocalizerFunc) {
        ptrLocalizerFunc = reinterpret_cast<LocalizerFunc>
            (qt_resolveS60PluginFunc(S60Plugin_LocalizedDirectoryName));
        if (!ptrLocalizerFunc)
            ptrLocalizerFunc = &defaultLocalizedDirectoryName;
    }

    QString rawPath = storageLocation(type);
    return ptrLocalizerFunc(rawPath);
}
Exemple #4
0
QString QDesktopServices::displayName(StandardLocation type)
{
    QString ret;

#ifdef Q_WS_S60
    QString rawPath = storageLocation(type);

    TRAPD(err,
        QT_TRYCATCH_LEAVING(
            CDirectoryLocalizer* localizer = CDirectoryLocalizer::NewL();
            CleanupStack::PushL(localizer);
            localizer->SetFullPath(qt_QString2TPtrC(QDir::toNativeSeparators(rawPath)));
            if (localizer->IsLocalized()) {
                TPtrC locName(localizer->LocalizedName());
                ret = qt_TDesC2QString(locName);
            }
            CleanupStack::PopAndDestroy(localizer);
        )
    )

    if (err != KErrNone)
Exemple #5
0
QString QDesktopServices::storageLocation(StandardLocation type)
{
    QString result;

#ifndef Q_OS_WINCE
        QSystemLibrary library(QLatin1String("shell32"));
#else
        QSystemLibrary library(QLatin1String("coredll"));
#endif // Q_OS_WINCE
    typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPWSTR, int, BOOL);
    static GetSpecialFolderPath SHGetSpecialFolderPath =
            (GetSpecialFolderPath)library.resolve("SHGetSpecialFolderPathW");
    if (!SHGetSpecialFolderPath)
        return QString();

    wchar_t path[MAX_PATH];

    switch (type) {
    case DataLocation:
#if defined Q_WS_WINCE
        if (SHGetSpecialFolderPath(0, path, CSIDL_APPDATA, FALSE))
#else
        if (SHGetSpecialFolderPath(0, path, CSIDL_LOCAL_APPDATA, FALSE))
#endif
            result = QString::fromWCharArray(path);
        if (!QCoreApplication::organizationName().isEmpty())
            result = result + QLatin1String("\\") + QCoreApplication::organizationName();
        if (!QCoreApplication::applicationName().isEmpty())
            result = result + QLatin1String("\\") + QCoreApplication::applicationName();
        break;

    case DesktopLocation:
        if (SHGetSpecialFolderPath(0, path, CSIDL_DESKTOPDIRECTORY, FALSE))
            result = QString::fromWCharArray(path);
        break;

    case DocumentsLocation:
        if (SHGetSpecialFolderPath(0, path, CSIDL_PERSONAL, FALSE))
            result = QString::fromWCharArray(path);
        break;

    case FontsLocation:
        if (SHGetSpecialFolderPath(0, path, CSIDL_FONTS, FALSE))
            result = QString::fromWCharArray(path);
        break;

    case ApplicationsLocation:
        if (SHGetSpecialFolderPath(0, path, CSIDL_PROGRAMS, FALSE))
            result = QString::fromWCharArray(path);
        break;

    case MusicLocation:
        if (SHGetSpecialFolderPath(0, path, CSIDL_MYMUSIC, FALSE))
            result = QString::fromWCharArray(path);
        break;

    case MoviesLocation:
        if (SHGetSpecialFolderPath(0, path, CSIDL_MYVIDEO, FALSE))
            result = QString::fromWCharArray(path);
        break;

    case PicturesLocation:
        if (SHGetSpecialFolderPath(0, path, CSIDL_MYPICTURES, FALSE))
            result = QString::fromWCharArray(path);
        break;

    case CacheLocation:
        // Although Microsoft has a Cache key it is a pointer to IE's cache, not a cache
        // location for everyone.  Most applications seem to be using a
        // cache directory located in their AppData directory
        return storageLocation(DataLocation) + QLatin1String("\\cache");

    case QDesktopServices::HomeLocation:
        return QDir::homePath(); break;

    case QDesktopServices::TempLocation:
        return QDir::tempPath(); break;

    default:
        break;
    }
    return result;
}
Exemple #6
0
QString LibraryInfo::dataPath()
{
    return storageLocation(QDesktopServices::DataLocation);
}
QString QDesktopServices::displayName(StandardLocation type)
{
    return storageLocation(type);
}
Exemple #8
0
void Project::save()
{
    QDir storageLocation(PeceraApplication::instance()->getProjectStorageLocation());
    if (!storageLocation.exists()) {
        if (!storageLocation.mkpath(storageLocation.absolutePath()))
            return;
    }

    QFile projectFile(storageLocation.filePath(m_name + ".db"));

    // From: http://www.sqlite.org/c3ref/open.html -- The encoding used for
    // the filename argument of sqlite3_open() and  sqlite3_open_v2() must be
    // UTF-8, not whatever codepage is currently defined.
    sqlite3* database;
    int rc = sqlite3_open(projectFile.fileName().toUtf8().data(), &database);
    if (rc) {
        handleSQLiteError(this, rc, database);
        return;
    }

    char* errorMessage = 0;
    rc = sqlite3_exec(database, "BEGIN;", 0, 0, &errorMessage);
    if (rc) {
        handleSQLiteError(this, rc, database, errorMessage);
        return;
    }

    rc = sqlite3_exec(database, "CREATE TABLE IF NOT EXISTS files(path TEXT, last_updated INT);", 0, 0, &errorMessage);
    if (rc) {
        handleSQLiteError(this, rc, database, errorMessage);
        return;
    }

    rc = sqlite3_exec(database, "DELETE FROM files;", 0, 0, &errorMessage);
    if (rc) {
        handleSQLiteError(this, rc, database, errorMessage);
        return;
    }

    sqlite3_stmt* statement;
    const char* sql = "INSERT OR REPLACE INTO files(path, last_updated) values(?, ?);";
    const char* tail;
    rc = sqlite3_prepare_v2(database, sql, strlen(sql), &statement, &tail);
    if (rc != SQLITE_OK) {
        handleSQLiteError(this, rc, database);
        return;
    }

    QMutexLocker lock(&m_filesMutex);
    QHash<QString, File*>::const_iterator i = m_files.begin();
    while (i != m_files.end()) {
        File* file = i.value();
        char* path = strdup(file->relativePath().toUtf8().data());
        sqlite3_bind_text(statement, 1, path, strlen(path), SQLITE_STATIC);
        sqlite3_bind_int64(statement, 2, file->lastUpdated());

        // BIG FIXME: Check the return value here and do the right thing.
        rc = sqlite3_step(statement);
        if (rc != SQLITE_DONE) {
            handleSQLiteError(this, rc, database);
            return;
        }

        rc = sqlite3_reset(statement);
        if (rc != SQLITE_OK) {
            handleSQLiteError(this, rc, database);
            return;
        }

        i++;
    }

    rc = sqlite3_finalize(statement);
    if (rc != SQLITE_OK) {
        handleSQLiteError(this, rc, database);
        return;
    }

    rc = sqlite3_exec(database, "END;", 0, 0, &errorMessage);
    if (rc) {
        handleSQLiteError(this, rc, database, errorMessage);
        return;
    }

    sqlite3_close(database);
}