This repository has been archived on 2020-04-18. You can view files and clone it, but cannot push or open issues or pull requests.
FediPotato/gui/src/window_main.cpp

178 lines
5.6 KiB
C++

/* This file is part of FediPotato.
* Copyright © 2020 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "window_main.hpp"
#include "channel.hpp"
#include "dialog_about.hpp"
#include "widget_post.hpp"
#include "fedipotato.hpp"
#include <QDesktopServices>
#include <QUrl>
#include <QStandardItem>
#include <QFont>
#include <QDebug>
namespace FediPotato
{
MainWindow::MainWindow(QMainWindow *parent)
: QMainWindow(parent)
, _model_channel(new QStandardItemModel(this))
{
setupUi(this);
// Add account for testing.
add_account();
// Add some post widgets for testing.
// FIXME: The widgets don't resize properly.
QTreeWidgetItem *item_root{treewidget_posts->invisibleRootItem()};
for (int i{0}; i < 2; ++i)
{
auto *pw1{new PostWidget(treewidget_posts)};
pw1->set_user("@user@example.com");
pw1->set_subject("Food");
pw1->set_content("I ate a whole lot of potatos today!");
pw1->set_avatar(":/images/no_avatar.svg");
pw1->show_hide_elements();
auto *item1{new QTreeWidgetItem};
item_root->addChild(item1);
treewidget_posts->setItemWidget(item1, 0, pw1);
auto *pw2{new PostWidget(treewidget_posts)};
pw2->set_user("@user@example.com");
pw2->set_subject("Pseudo-latin");
pw2->set_content("Aliquam feugiat tellus ut neque. Sed bibendum. "
"Mauris ac felis vel velit tristique imperdiet.");
pw2->show_hide_elements();
auto *item2{new QTreeWidgetItem};
item1->addChild(item2);
treewidget_posts->setItemWidget(item2, 0, pw2);
auto *pw4{new PostWidget(treewidget_posts)};
pw4->set_user("@user@example.com");
pw4->set_content("Nam vestibulum accumsan nisl. "
"Praesent fermentum tempor tellus. Fusce commodo. "
"Phasellus purus. "
"Praesent fermentum tempor tellus.");
pw4->show_hide_elements();
auto *item4{new QTreeWidgetItem};
item2->addChild(item4);
treewidget_posts->setItemWidget(item4, 0, pw4);
auto *pw3{new PostWidget(treewidget_posts)};
pw3->set_user("@user@example.com");
pw3->set_content("👍");
pw3->show_hide_elements();
auto *item3{new QTreeWidgetItem};
item1->addChild(item3);
treewidget_posts->setItemWidget(item3, 0, pw3);
}
}
void MainWindow::add_account()
{
QStandardItem *item_root{_model_channel->invisibleRootItem()};
auto *item_account{new ChannelItem("@user@example.com", id_channel::none)};
item_root->appendRow(item_account);
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
item_account->appendRow(new ChannelItem("Home Timeline",
id_channel::tl_home));
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
item_account->appendRow(new ChannelItem("Instance Timeline",
id_channel::tl_instance));
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
item_account->appendRow(new ChannelItem("Federated Timeline",
id_channel::tl_federated));
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
item_account->appendRow(new ChannelItem("Conversations",
id_channel::conversations));
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
item_account->appendRow(new ChannelItem("#tea",
id_channel::hashtag));
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
item_account->appendRow(new ChannelItem("#FediPotato",
id_channel::hashtag));
treeview_channel->setModel(_model_channel);
treeview_channel->expandAll();
QFont font_channel{treeview_channel->font()};
font_channel.setPointSize(font_channel.pointSize() + 2);
treeview_channel->setFont(font_channel);
FediPotato acc("FediPotato");
}
void MainWindow::show_about()
{
auto *dlg{new AboutDialog()}; // NOLINT(cppcoreguidelines-owning-memory)
dlg->show();
}
void MainWindow::open_website()
{
QDesktopServices::openUrl(QUrl("http://fedipotato.org/"));
}
void MainWindow::clicked_channel(const QModelIndex &index)
{
auto item{dynamic_cast<ChannelItem*>(_model_channel->itemFromIndex(index))};
switch (item->identifier())
{
case id_channel::none:
{
qDebug() << "None.";
break;
}
case id_channel::tl_home:
{
qDebug() << "Home TL.";
break;
}
case id_channel::tl_instance:
{
qDebug() << "Instance TL.";
break;
}
case id_channel::tl_federated:
{
qDebug() << "Federated TL.";
break;
}
case id_channel::conversations:
{
qDebug() << "Conversations.";
break;
}
case id_channel::hashtag:
{
qDebug() << "Hashtag.";
break;
}
case id_channel::filter:
{
qDebug() << "Filter.";
break;
}
}
}
} // namespace FediPotato