<commit_before>/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of duihome.
**
** If you have questions regarding the use of this file, please contact
** Nokia at <EMAIL>.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#include <QFlags>
#include <QDir>
#include <DuiActionProvider>
#include <DuiApplicationIfProxy>
#include <DuiDesktopEntry>
#include "duifiledatastore.h"
#include "launcherdatastore.h"

#ifdef ENABLE_QTTRACKER
#include <QtTracker/ontologies/nfo.h>
#endif

#include "launcher.h"
#include "launcherbutton.h"

static const char* const FILE_FILTER = "*.desktop";

Launcher::Launcher(DuiWidget *parent) :
    DuiWidgetController(new LauncherModel, parent),
    dataStore(NULL),
    initialized(false)
{
    pathsForDesktopEntries << APPLICATIONS_DIRECTORY;
#ifdef TESTABILITY_ON
    pathsForDesktopEntries << QDir::tempPath();
#endif
    supportedDesktopEntryFileTypes << "Application" << "Link";
}

Launcher::~Launcher()
{
    delete dataStore;
}

void Launcher::activateLauncher()
{
    if (!initialized) {

        if (!QDir::root().exists(QDir::homePath() + "/.config/duihome")) {
            QDir::root().mkpath(QDir::homePath() + "/.config/duihome");
        }
	
	DuiFileDataStore* backendStore = new DuiFileDataStore(QDir::homePath() + "/.config/duihome/launcherbuttons.data");

        dataStore = new LauncherDataStore(backendStore);

        // restore previous button order from datastore
        restoreButtonsFromDataStore();

        // Update the button list according to watched directories
        updateButtonList();

#ifdef ENABLE_QTTRACKER
        // Query tracker for bookmarks (shortcuts)
        SopranoLive::RDFSelect select;
        select.addColumn("iri", SopranoLive::RDFVariable::fromType<SopranoLive::nfo::Bookmark>());
        shortcutItemModel = tracker()->modelQuery(select);
#endif

        // Start watching the applications directory for changes
        connect(&watcher, SIGNAL(directoryChanged(const QString)), this, SLOT(updateButtonListFromDirectory(const QString)));
        foreach (const QString& dir, pathsForDesktopEntries) {
            watcher.addPath(dir);
        }
        // The launcher has now been initialized
        initialized = true;
    } else {
        updateButtonList();
    }
}

void Launcher::updateButtonList()
{
    // this updates for all paths
    updateButtonListFromEntries(pathsForDesktopEntries,
                                pathsForDesktopEntries,
                                FILE_FILTER,
                                supportedDesktopEntryFileTypes
                                );
}

void Launcher::updateButtonListFromDirectory(const QString &path)<commit_msg>Changes: The launcher button list was needlessly updated every time the launhcer was brought visible.<commit_after>/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of duihome.
**
** If you have questions regarding the use of this file, please contact
** Nokia at <EMAIL>.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#include <QFlags>
#include <QDir>
#include <DuiActionProvider>
#include <DuiApplicationIfProxy>
#include <DuiDesktopEntry>
#include "duifiledatastore.h"
#include "launcherdatastore.h"

#ifdef ENABLE_QTTRACKER
#include <QtTracker/ontologies/nfo.h>
#endif

#include "launcher.h"
#include "launcherbutton.h"

static const char* const FILE_FILTER = "*.desktop";

Launcher::Launcher(DuiWidget *parent) :
    DuiWidgetController(new LauncherModel, parent),
    dataStore(NULL),
    initialized(false)
{
    pathsForDesktopEntries << APPLICATIONS_DIRECTORY;
#ifdef TESTABILITY_ON
    pathsForDesktopEntries << QDir::tempPath();
#endif
    supportedDesktopEntryFileTypes << "Application" << "Link";
}

Launcher::~Launcher()
{
    delete dataStore;
}

void Launcher::activateLauncher()
{
    if (!initialized) {

        if (!QDir::root().exists(QDir::homePath() + "/.config/duihome")) {
            QDir::root().mkpath(QDir::homePath() + "/.config/duihome");
        }
	
	DuiFileDataStore* backendStore = new DuiFileDataStore(QDir::homePath() + "/.config/duihome/launcherbuttons.data");

        dataStore = new LauncherDataStore(backendStore);

        // restore previous button order from datastore
        restoreButtonsFromDataStore();

        // Update the button list according to watched directories
        updateButtonList();

#ifdef ENABLE_QTTRACKER
        // Query tracker for bookmarks (shortcuts)
        SopranoLive::RDFSelect select;
        select.addColumn("iri", SopranoLive::RDFVariable::fromType<SopranoLive::nfo::Bookmark>());
        shortcutItemModel = tracker()->modelQuery(select);
#endif

        // Start watching the applications directory for changes
        connect(&watcher, SIGNAL(directoryChanged(const QString)), this, SLOT(updateButtonListFromDirectory(const QString)));
        foreach (const QString& dir, pathsForDesktopEntries) {
            watcher.addPath(dir);
        }
        // The launcher has now been initialized
        initialized = true;
    }
}

void Launcher::updateButtonList()
{
    // this updates for all paths
    updateButtonListFromEntries(pathsForDesktopEntries,
                                pathsForDesktopEntries,
                                FILE_FILTER,
                                supportedDesktopEntryFileTypes
                                );
}

void Launcher::updateButtonListFromDirectory(const QString &path)
{'fraction_non_alphanumeric': 0.14881605770738593, 'fraction_numerical': 0.0018817625842872823, 'mean_word_length': 3.669106881405564, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2049015', 'n_tokens_mistral': 1790, 'n_tokens_neox': 1677, 'n_words': 453}