Ejemplo n.º 1
0
	void TodoTab::handleImport ()
	{
		const QString& filename = QFileDialog::getOpenFileName (this,
				tr ("Import tasks"),
				QDir::homePath (),
				tr ("iCalendar files (*.ics)"));

		QFile file (filename);
		if (!file.open (QIODevice::ReadOnly))
		{
			QMessageBox::critical (this,
					tr ("Tasks import"),
					tr ("Unable to open %1: %2.")
						.arg ("<em>" + filename + "</em>")
						.arg (file.errorString ()));
			return;
		}

		const auto& items = ICalParser ().Parse (file.readAll ());
		if (items.isEmpty ())
			return;

		ItemsMergeDialog dia (items.size (), this);
		if (dia.exec () != QDialog::Accepted)
			return;

		auto storage = Core::Instance ().GetTodoManager ()->GetTodoStorage ();
		auto ourItems = storage->GetAllItems ();
		for (const auto& item : items)
		{
			const auto& itemId = item->GetID ();
			auto pos = std::find_if (ourItems.begin (), ourItems.end (),
					[&itemId] (const auto& ourItem) { return ourItem->GetID () == itemId; });
			if (pos != ourItems.end ())
			{
				if (dia.GetPriority () == ItemsMergeDialog::Priority::Imported)
				{
					(*pos)->CopyFrom (item);
					storage->HandleUpdated (*pos);
				}
				continue;
			}

			const auto& itemTitle = item->GetTitle ();
			pos = std::find_if (ourItems.begin (), ourItems.end (),
					[itemTitle] (const auto& ourItem) { return ourItem->GetTitle () == itemTitle; });
			if (pos != ourItems.end ())
			{
				if (dia.GetPriority () == ItemsMergeDialog::Priority::Imported &&
						dia.GetSameTitle () == ItemsMergeDialog::SameTitle::Merge)
				{
					(*pos)->CopyFrom (item);
					storage->HandleUpdated (*pos);
				}
				continue;
			}

			storage->AddItem (item);
		}
	}
Ejemplo n.º 2
0
	void TodoTab::handleImport ()
	{
		const QString& filename = QFileDialog::getOpenFileName (this,
				tr ("Import tasks"),
				QDir::homePath (),
				tr ("iCalendar files (*.ics)"));

		QFile file (filename);
		file.open (QIODevice::ReadOnly);
		auto items = ICalParser ().Parse (file.readAll ());
		if (items.isEmpty ())
			return;

		ItemsMergeDialog dia (items.size (), this);
		if (dia.exec () != QDialog::Accepted)
			return;

		auto storage = Core::Instance ().GetTodoManager ()->GetTodoStorage ();
		auto ourItems = storage->GetAllItems ();
		Q_FOREACH (auto item, items)
		{
			const auto& itemId = item->GetID ();
			auto pos = std::find_if (ourItems.begin (), ourItems.end (),
					[&itemId] (decltype (ourItems.front ()) ourItem) { return ourItem->GetID () == itemId; });
			if (pos != ourItems.end ())
			{
				if (dia.GetPriority () == ItemsMergeDialog::Priority::Imported)
				{
					(*pos)->CopyFrom (item);
					storage->HandleUpdated (*pos);
				}
				continue;
			}

			const auto& itemTitle = item->GetTitle ();
			pos = std::find_if (ourItems.begin (), ourItems.end (),
					[itemTitle] (decltype (ourItems.front ()) ourItem) { return ourItem->GetTitle () == itemTitle; });
			if (pos != ourItems.end ())
			{
				if (dia.GetPriority () == ItemsMergeDialog::Priority::Imported &&
						dia.GetSameTitle () == ItemsMergeDialog::SameTitle::Merge)
				{
					(*pos)->CopyFrom (item);
					storage->HandleUpdated (*pos);
				}
				continue;
			}

			storage->AddItem (item);
		}
	}