Newer
Older
dischrome / dischrome.cpp
@TAM (Teppei Tamra) TAM (Teppei Tamra) on 30 Mar 2018 2 KB initialized and completed. goodnight.
/***

The MIT License

Copyright (c) 2018 Teppei Tamra (TAM)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

***/

#include "dischrome.h"
#include <QApplication>
#include <QStandardPaths>
#include <QFile>
#include <QImage>
#include <QPixmap>
#include <QIcon>
#include <QTimer>
#include <QDateTime>
#include <QMenu>

DisChrome::DisChrome()
{
    QImage icon(":/icons/thumbsdown.svg");
    setIcon(QIcon(QPixmap::fromImage(icon.scaled(QSize(44,44)))));
    now = false;
    auto menu = new QMenu();
    auto quitaction =new QAction(tr("Quit"),this);
    connect(quitaction,&QAction::triggered,[](){
        QApplication::quit();
    });
    menu->addAction(quitaction);
    setContextMenu(menu);
    check();
}

bool DisChrome::findChromeInstance()
{
    QFile file(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/google-chrome/");
    return file.exists();
}

const QString DisChrome::message()
{
    int t = QDateTime::currentMSecsSinceEpoch() % 6;
    switch (t) {
    case 0:
        return tr("w3m is faster than chrome.");
        break;
    case 1:
        return tr("lynx is safer than chrome.");
        break;
    case 2:
        return tr("Firefox icon is cute than chrome icon.");
        break;
    case 3:
        return tr("Falkon is more cool for KDE users than chrome.");
        break;
    case 4:
        return tr("wget is more faster and safer than chrome.");
        break;
    case 5:
        return tr("wget is more faster and safer than chrome.");
        break;
    default:
        return "";
        break;
    }
}

void DisChrome::check()
{
    if (findChromeInstance()) {
        if (!now) {
            now = true;
            showMessage(tr("Are you still using chrome?"),message());
        }
    } else {
        now = false;
    }
    QTimer::singleShot(1000,this,&DisChrome::check);
}