Exemplo n.º 1
0
/**
 * Update the local favorites file and add thumb if necessary.
 */
void favoriteWindow::save()
{
	Favorite oldFav = favorite;
	favorite = Favorite(ui->tagLineEdit->text(), ui->noteSpinBox->value(), ui->lastViewedDateTimeEdit->dateTime());

	if (QFile::exists(ui->imageLineEdit->text()))
	{
		QPixmap img(ui->imageLineEdit->text());
		if (!img.isNull())
		{ favorite.setImage(img); }
	}
	else if (oldFav.getName() != ui->tagLineEdit->text() && QFile::exists(savePath("thumbs/" + oldFav.getName(true) + ".png")))
	{ QFile::rename(savePath("thumbs/" + oldFav.getName(true) + ".png"), savePath("thumbs/" + favorite.getName(true) + ".png")); }

	QFile f(savePath("favorites.txt"));
	f.open(QIODevice::ReadOnly);
		QString favorites = f.readAll();
	f.close();

	favorites.replace("\r\n", "\n").replace("\r", "\n").replace("\n", "\r\n");
	favorites.remove(oldFav.getName() + "|" + QString::number(oldFav.getNote()) + "|" + oldFav.getLastViewed().toString(Qt::ISODate) + "\r\n");
	favorites += favorite.getName() + "|" + QString::number(favorite.getNote()) + "|" + favorite.getLastViewed().toString(Qt::ISODate) + "\r\n";

	f.open(QIODevice::WriteOnly);
		f.write(favorites.toUtf8());
	f.close();

	emit favoritesChanged();
}
Exemplo n.º 2
0
void FavoriteTest::testFromString()
{
	QString from = "fate/stay_night|50|2016-07-02T16:35:12";

	QDateTime date = QDateTime::fromString("2016-07-02 16:35:12", "yyyy-MM-dd HH:mm:ss");
	Favorite expected("fate/stay_night", 50, date);
	Favorite actual = Favorite::fromString("", from);

	QCOMPARE(actual.getName(), expected.getName());
	QCOMPARE(actual.getNote(), expected.getNote());
	QCOMPARE(actual.getLastViewed(), expected.getLastViewed());
}
Exemplo n.º 3
0
void favoritesTab::loadFavorite(QString name)
{
	int index = name.isEmpty() ? m_currentFav : m_favorites.indexOf(name);
	if (index < 0)
		return;

	Favorite fav = m_favorites[index];
	m_currentTags = fav.getName();
	m_loadFavorite = fav.getLastViewed();

	ui->widgetResults->show();
	load();
}