<commit_before>/* Copyright (c) 2010  <NAME> <<EMAIL>>
 *
 * This file is part of poppler-glibmm.
 *
 * poppler-glibmm is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 2.1 of the License,
 * or (at your option) any later version.
 *
 * poppler-glibmm is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "demo-window.h"
#include "auth-dialog.h"

#include <gtkmm/application.h>
#include <glibmm/timer.h>
#include <poppler-glibmm/init.h>
#include <poppler-glibmm/document.h>
#include <poppler-glibmm/error.h>
#include <iostream>
#include <iomanip>

int main (int argc, char **argv)
{
	if (argc != 2)
	{
		std::cout << "Usage: poppler-glibmm-demo file" << std::endl;
		return 1;
	}

	Poppler::init();

	// Hack to work around a bug in recent versions of Gtk/Gtkmm
	int _argc = 1;
	char** _argv = &argv[0];
	Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(_argc, _argv,
			"org.poppler-glibmm.demo", Gio::APPLICATION_HANDLES_OPEN);

	Glib::RefPtr<Gio::File> file = Gio::File::create_for_commandline_arg(argv[1]);

	Glib::RefPtr<Poppler::Document> document;
	{
		std::string password;
		AuthDialog dialog(file->get_basename());
		do
		{
			password = dialog.GetPassword();
			Glib::Timer timer;
			try
			{
				document = Poppler::Document::new_from_file(file->get_uri(), password);
			}
			catch (Poppler::Error exception)
			{
				continue;
			}
			catch (Glib::Error exception)
			{
				return 1;
			}
			timer.stop();
			std::cout << "Document successfully loaded in "
				<< std::fixed << std::setprecision(4) << timer.elapsed() << " seconds\n";
		} while (!document && dialog.run() == Gtk::RESPONSE_OK);
	}

	if (!document) return 1;

	// Main window
	DemoWindow window(document);
	app->run(window);

	return 0;
}<commit_msg>Use the new_from_gio_file method to construct the document.<commit_after>/* Copyright (c) 2010  <NAME> <<EMAIL>>
 *
 * This file is part of poppler-glibmm.
 *
 * poppler-glibmm is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 2.1 of the License,
 * or (at your option) any later version.
 *
 * poppler-glibmm is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "demo-window.h"
#include "auth-dialog.h"

#include <gtkmm/application.h>
#include <glibmm/timer.h>
#include <poppler-glibmm/init.h>
#include <poppler-glibmm/document.h>
#include <poppler-glibmm/error.h>
#include <iostream>
#include <iomanip>

int main (int argc, char **argv)
{
	if (argc != 2)
	{
		std::cout << "Usage: poppler-glibmm-demo file" << std::endl;
		return 1;
	}

	Poppler::init();

	// Hack to work around a bug in recent versions of Gtk/Gtkmm
	int _argc = 1;
	char** _argv = &argv[0];
	Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(_argc, _argv,
			"org.poppler-glibmm.demo", Gio::APPLICATION_HANDLES_OPEN);

	Glib::RefPtr<Gio::File> file = Gio::File::create_for_commandline_arg(argv[1]);

	Glib::RefPtr<Poppler::Document> document;
	{
		std::string password;
		AuthDialog dialog(file->get_basename());
		do
		{
			password = dialog.GetPassword();
			Glib::Timer timer;
			try
			{
				document = Poppler::Document::new_from_gio_file(file, password);
			}
			catch (Poppler::Error exception)
			{
				continue;
			}
			catch (Glib::Error exception)
			{
				return 1;
			}
			timer.stop();
			std::cout << "Document successfully loaded in "
				<< std::fixed << std::setprecision(4) << timer.elapsed() << " seconds\n";
		} while (!document && dialog.run() == Gtk::RESPONSE_OK);
	}

	if (!document) return 1;

	// Main window
	DemoWindow window(document);
	app->run(window);

	return 0;
}
{'fraction_non_alphanumeric': 0.13489409141583056, 'fraction_numerical': 0.006688963210702341, 'mean_word_length': 4.0291479820627805, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6398461', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1488, 'n_words': 451}