Пример #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();
}
Пример #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());
}
Пример #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();
}
Пример #4
0
/**
 * Update the local favorites file and add thumb if necessary.
 */
void favoriteWindow::save()
{
	Favorite oldFav = m_favorite;

	// Update monitors
	int interval = ui->spinMonitoringInterval->value() * 60;
	Site *site = m_profile->getSites().value(ui->comboMonitoringSource->currentText());
	QList<Monitor> monitors = oldFav.getMonitors();
	if (interval == 0)
	{ monitors.clear(); }
	else if (monitors.isEmpty())
	{ monitors.append(Monitor(site, interval, QDateTime::currentDateTimeUtc())); }
	else
	{
		Monitor rep(site, interval, monitors[0].lastCheck());
		monitors[0] = rep;
	}

	m_favorite = Favorite(ui->tagLineEdit->text(), ui->noteSpinBox->value(), ui->lastViewedDateTimeEdit->dateTime(), monitors);
	m_favorite.setImagePath(savePath("thumbs/" + m_favorite.getName(true) + ".png"));

	if (oldFav.getName() != m_favorite.getName())
	{
		if (QFile::exists(savePath("thumbs/" + oldFav.getName(true) + ".png")))
		{ QFile::rename(savePath("thumbs/" + oldFav.getName(true) + ".png"), m_favorite.getImagePath()); }
		m_profile->removeFavorite(oldFav);
	}

	if (QFile::exists(ui->imageLineEdit->text()))
	{
		QPixmap img(ui->imageLineEdit->text());
		if (!img.isNull())
		{ m_favorite.setImage(img); }
	}
	m_profile->addFavorite(m_favorite);
}
Пример #5
0
bool operator==(const Favorite& lhs, const Favorite& rhs)
{ return lhs.getName().toLower() == rhs.getName().toLower(); }