Re: [Tails-dev] minitube (Youtube client)

Borrar esta mensaxe

Responder a esta mensaxe
Autor: Alessandro Grassi
Data:  
Para: tails-dev
Asunto: Re: [Tails-dev] minitube (Youtube client)
Hi,

2012/12/18, intrigeri <intrigeri@???>:
> Did you already send this patch to them, by the way?
> (If not, I encourage you to do so :)

I sent a mail to the mantainer but he didn't answer (yet).

> Great! How about searching the source for code that accesses the
> history (probably basing the search on the place / name of the files /
> storage methods that contain the history) too? This code may, or may
> not, contain the "recent" word.

I found it. Settings file is accessede using the QSettings class, so
for example this code removes keywords history:

MainWindow.cpp
-----------------------------
.....
void MainWindow::clearRecentKeywords() {
    QSettings settings;
    settings.remove("recentKeywords");
    settings.remove("recentChannels");
    searchView->updateRecentKeywords();
    searchView->updateRecentChannels();
    statusBar()->showMessage(tr("Your privacy is now safe"));
}
.....


The following code saves the keyword after a search (with
settings.setValue(recentKeywordsKey, keywords); ):

ListModel.cpp
----------------------
.....
static const QString recentKeywordsKey = "recentKeywords";
static const QString recentChannelsKey = "recentChannels";
.....
void ListModel::addVideo(Video* video) {

    connect(video, SIGNAL(gotThumbnail()), this, SLOT(updateThumbnail()));


    beginInsertRows(QModelIndex(), videos.size(), videos.size());
    videos << video;
    endInsertRows();


    // first result!
    if (videos.size() == 1) {


        // manualplay
        QSettings settings;
        if (!settings.value("manualplay", false).toBool())
            setActiveRow(0);


        // save keyword
        QString query = searchParams->keywords();
        if (!query.isEmpty() && !searchParams->isTransient()) {
            if (query.startsWith("http://")) {
                // Save the video title
                query += "|" + videos.first()->title();
            }
            QStringList keywords =
settings.value(recentKeywordsKey).toStringList();
            keywords.removeAll(query);
            keywords.prepend(query);
            while (keywords.size() > 10)
                keywords.removeLast();
            settings.setValue(recentKeywordsKey, keywords);
        }


        // save channel
        QString channel = searchParams->author();
        if (!channel.isEmpty() && !searchParams->isTransient()) {
            QSettings settings;
            QStringList channels =
settings.value(recentChannelsKey).toStringList();
            channels.removeAll(channel);
            channels.prepend(channel);
            while (channels.size() > 10)
                channels.removeLast();
            settings.setValue(recentChannelsKey, channels);
        }


    }


}
......

and this last function loads the keywords (with
settings.value(recentKeywordsKey) ) and displays them under the serch
box:

SearchView.cpp
-------------------------
.....
static const QString recentKeywordsKey = "recentKeywords";
static const QString recentChannelsKey = "recentChannels";
.....
void SearchView::updateRecentKeywords() {

    // cleanup
    QLayoutItem *item;
    while ((item = recentKeywordsLayout->takeAt(1)) != 0) {
        item->widget()->close();
        delete item;
    }


    // load
    QSettings settings;
    QStringList keywords = settings.value(recentKeywordsKey).toStringList();
    recentKeywordsLabel->setVisible(!keywords.isEmpty());
    The::globalActions()->value("clearRecentKeywords")->setEnabled(!keywords.isEmpty());


    foreach (QString keyword, keywords) {
        QString link = keyword;
        QString display = keyword;
        if (keyword.startsWith("http://") || keyword.startsWith("https://")) {
            int separator = keyword.indexOf("|");
            if (separator > 0 && separator + 1 < keyword.length()) {
                link = keyword.left(separator);
                display = keyword.mid(separator+1);
            }
        }
        bool needStatusTip = false;
        if (display.length() > 24) {
            display.truncate(24);
            display.append("...");
            needStatusTip = true;
        }
        QLabel *itemLabel = new QLabel("<a href=\"" + link
                                       + "\"
style=\"color:palette(text); text-decoration:none\">"
                                       + display + "</a>", this);
        itemLabel->setAttribute(Qt::WA_DeleteOnClose);
        itemLabel->setProperty("recentItem", true);
        itemLabel->setMaximumWidth(queryEdit->width() + watchButton->width());
        // itemLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
        // Make links navigable with the keyboard too
        itemLabel->setTextInteractionFlags(Qt::LinksAccessibleByKeyboard

| Qt::LinksAccessibleByMouse);

        if (needStatusTip)
            itemLabel->setStatusTip(link);
        connect(itemLabel, SIGNAL(linkActivated(QString)), this,
SLOT(watchKeywords(QString)));
        recentKeywordsLayout->addWidget(itemLabel);
    }


}
.....

There is a similar function for recent channels. There are no other
references to "recentKeywords" and "recentChannels" in the code.

Greetings
Alessandro