Exemple #1
0
Client::Client(int &argc, char **argv, int appflags) :
		QApplication(argc, argv, appflags) {
	setAttribute(Qt::AA_UseHighDpiPixmaps);

	setQuitOnLastWindowClosed(false);
	applyLocale(QLocale::system().name());
	// Parsing arguments
	QCommandLineParser parser;
	QCommandLineOption attach_option(QStringList() << "a" << "attach", tr("Attach to running daemon instead of creating a new one."), "url");
	parser.addOption(attach_option);
	parser.addPositionalArgument("url", tr("The \"lvlt:\" URL to open."));
	parser.process(*this);

	QString link;

	if(parser.positionalArguments().size() > 0){
		QRegularExpression link_regex("lvlt:.*");
		auto link_index = parser.positionalArguments().indexOf(link_regex);
		if(link_index != -1)
			link = parser.positionalArguments().at(link_index);
	}

	// Creating components
	single_channel_ = std::make_unique<SingleChannel>(link);

	daemon_ = std::make_unique<Daemon>();
	control_client_ = std::make_unique<ControlClient>();
	if(parser.isSet(attach_option))
		control_client_->connectDaemon(QUrl(parser.value(attach_option)));
	else {
		connect(daemon_.get(), &Daemon::daemonReady, control_client_.get(), &ControlClient::connectDaemon);
		daemon_->launch();
	}

	updater_ = new Updater(this);

	main_window_ = std::make_unique<MainWindow>(*this);

	// Connecting signals & slots
	connect(single_channel_.get(), &SingleChannel::showMainWindow, main_window_.get(), &QMainWindow::show);
	connect(single_channel_.get(), &SingleChannel::openLink, this, &Client::openLink);

	connect(control_client_.get(), &ControlClient::ControlJsonReceived, main_window_.get(), &MainWindow::handleControlJson);

	connect(main_window_.get(), &MainWindow::newConfigIssued, control_client_.get(), &ControlClient::sendConfigJson);
	connect(main_window_.get(), &MainWindow::folderAdded, control_client_.get(), &ControlClient::sendAddFolderJson);
	connect(main_window_.get(), &MainWindow::folderRemoved, control_client_.get(), &ControlClient::sendRemoveFolderJson);

	// Initialization complete!
	if(!link.isEmpty())
		openLink(link);
}
Exemple #2
0
bool check_links(QString text)
{

    QRegularExpression link_regex("http://restbase.wikitolearn.org/en.wikitolearn.org/v1/media/math/render/svg");
    QRegularExpressionMatch contain = link_regex.match(text);
    qDebug() << contain;

    QRegularExpression png_regex("http://pool.wikitolearn.org");
    QRegularExpressionMatch png = png_regex.match(text);
    qDebug() << png;

    if(contain.capturedLength() > 0 && png.capturedLength() > 0)
    {
        // change the status to true , so that i can download dependencies
        math_svg = true;
        image_png = true;
        return true;
    }

    else if(contain.capturedLength() > 0)
    {
        // change the status to true , to download the dependencies
        math_svg = true;
        return  true;
    }
    else if(png.capturedLength() > 0)
    {
        // change the status to true , to download the images
        image_png = true;
        return true;
    }
    else
    {
        return false;
    }

}
Exemple #3
0
bool save_images(QString filename , int pageid) // image saving function
{
    QString content , newpath ;
    qDebug() << filename +" <- html filename ";
    QFile file(filename);
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        qDebug() <<"unable to open file";
        return false;
    }
    else{
        content = file.readAll(); // read contents of html file
        qDebug() <<"testing : " << content;
        //  download images here

        QRegularExpression link_regex("\"http://restbase.wikitolearn.org/en.wikitolearn.org/v1/media/math/render/svg/(.*?)\"");
        QRegularExpressionMatchIterator links = link_regex.globalMatch(content);


        QRegularExpression png_regex("src=\"http://pool.wikitolearn.org(.*?).png");
        QRegularExpressionMatchIterator png = png_regex.globalMatch(content);


        while (links.hasNext()) {

            // got the links and constructing the url
            QRegularExpressionMatch match = links.next();
            qDebug() << match;

            QString down_link = match.captured(1);
            //content = content.replace(down_link,down_link+".svg");
            down_link = "http://restbase.wikitolearn.org/en.wikitolearn.org/v1/media/math/render/svg/" + down_link;
            down_links << down_link;  //prepare list of downloads
            //start downloading images

            // clearn img src in local html file
            QString d = content.replace("http://restbase.wikitolearn.org/en.wikitolearn.org/v1/media/math/render/svg/",""); //clean img src in local html file
            qDebug() << imgpath ;
            newpath = d.replace("\" class=\"mwe-math",".svg\" class=\"mwe-math");
        }

        while (png.hasNext()){
            QRegularExpressionMatch png_match = png.next();
            QString png_links = png_match.captured(1);
            qDebug() << "png_links" << png_links;

            png_links = "http://pool.wikitolearn.org"+png_links+".png";
            qDebug() << "png_links" << png_links;
            png_down_links << png_links;
            png_links = png_links.replace("http://pool.wikitolearn.org","");
            qDebug() << "png_links" << png_links;
            png_links = png_links.replace(".png","");
            qDebug() << "png_links" << png_links;
            newpath   = newpath.replace(png_links,"");

            // converting the png urls to hashes
            // file name == hash of the url

            QByteArray hash = png_links.toUtf8();
            QString hash_me = QString(QCryptographicHash::hash((hash),QCryptographicHash::Md5).toHex());
            png_links = hash_me ;
            qDebug() << "hash_me" << hash_me;
            png_hash << hash_me;


            png_links = png_links+".png";
            qDebug() << png_links;
            newpath   = newpath.replace("http://pool.wikitolearn.org.png",png_links);


        }



        qDebug() << "size" << down_links.size(); // got the number of files to download

        qDebug() << down_links; //got the list of downloads
        qDebug() << png_down_links;
        qDebug() << png_hash;
        file.close();

    }

    if(!file.open(QIODevice::WriteOnly | QIODevice::Text))
    {
        qDebug() <<"unable to write to file";
        return false;
    }

    else
    {
        qDebug() <<"write to file here";
        QTextStream out(&file);

        QString styling = "<head>"
                          "<link rel=\"stylesheet\" type=\"text/css\" href=\"main.css\">"
                          "<link rel=\"stylesheet\" type=\"text/css\" href=\"wikitolearnskin.css\">"
                          "<link rel=\"stylesheet\" type=\"text/css\" href=\"bootstrap.css\">"
                          "</head>";

        newpath = styling +newpath;

        // added the css links to the page

        out << newpath;
        // qDebug()<<newpath;

        file.close();

        // move html file and css to their respective folder
        QString fname = QString::number(pageid);
        QDir dir(data_path);
        dir.cd("WTL_appdata");
        QString temp_name = dir.absoluteFilePath(filename);
        QString new_name = temp_name.replace(".html","");
        QString css_path = new_name;
        new_name = new_name + "/" + fname +".html";
        file.rename(filename,new_name);

        // copy required css files.
        css_path = css_path + "/main.css";
        file.copy(dir.absoluteFilePath("main.css"),css_path);

        css_path = css_path.replace("/main.css","/bootstrap.css");
        file.copy(dir.absoluteFilePath("bootstrap.css"),css_path);

        css_path = css_path.replace("/bootstrap.css","/wikitolearnskin.css");
        file.copy(dir.absoluteFilePath("wikitolearnskin.css"),css_path);


    }

    if(math_svg!=false){


        // if there are  maths ml content (SVG) download them
        dbmanager *d = new dbmanager(0) ;
        d->doDownload(down_links);
    }

    if(image_png!=false){


        //if there are images (png) download them
        dbmanager *p = new dbmanager(0) ;
        p->png_download(png_down_links, png_hash);
    }
    return true ;

}