diff options
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/status_info.cpp | 20 | ||||
-rw-r--r-- | src/widgets/status_info.h | 10 | ||||
-rw-r--r-- | src/widgets/tab_activity_list.cpp | 8 | ||||
-rw-r--r-- | src/widgets/tab_actor_info.cpp | 1 | ||||
-rw-r--r-- | src/widgets/tab_actor_info.h | 2 |
5 files changed, 17 insertions, 24 deletions
diff --git a/src/widgets/status_info.cpp b/src/widgets/status_info.cpp index 8ff90df..e3fe968 100644 --- a/src/widgets/status_info.cpp +++ b/src/widgets/status_info.cpp @@ -24,7 +24,6 @@ StatusInfoWidget::~StatusInfoWidget() { worker_thread.quit(); worker_thread.wait(); - delete displayed_activity; delete ui; } @@ -46,9 +45,9 @@ void StatusInfoWidget::resizeEvent(QResizeEvent* event) { } void StatusInfoWidget::show_list_item(StatusListItem* new_item) { - qDebug() << "got item" << new_item << "old is" << displayed_item << displayed_activity; + qDebug() << "got item" << new_item << "old is" << displayed_item << displayed_activity.get(); if (new_item != displayed_item) { - delete displayed_activity; displayed_activity = nullptr; + displayed_activity.reset(); displayed_item = new_item; emit do_process_item(new_item); } @@ -56,14 +55,9 @@ void StatusInfoWidget::show_list_item(StatusListItem* new_item) { // Update the GUI with the displayed Activity. // Has to be done on the GUI thread, no other way in Qt -void StatusInfoWidget::postProcess(const QString &html, APActivity* activity) { - // Make sure to not delete the displayed_activity if we are reprocessing it after a resize event, else you get a crash that requires nasty debugging (don't ask how i found out ;) - if (activity != displayed_activity) { - // We are doing "double" deletion of old displayed_activity but sometimes that's important when really scrubbing the search results bar very quickly (we sometimes do reach that code and it hopefully helps against memory leaks) - if (displayed_activity) - delete displayed_activity; - displayed_activity = activity; - } +void StatusInfoWidget::postProcess(const QString &html, APActivityPtr activity) { + // This shoudln't memory leak as we are now using smart pointers + displayed_activity = activity; ui->statusInfoText->setHtml(html); } @@ -74,11 +68,11 @@ void StatusInfoWidget::postProcess(const QString &html, APActivity* activity) { */ void StatusInfoWidgetWorker::process_item(StatusListItem* item) { - APActivity* activity = item->get_activity(); + APActivityPtr activity = item->get_activity(); process_activity(activity); } -void StatusInfoWidgetWorker::process_activity(APActivity* activity) { +void StatusInfoWidgetWorker::process_activity(APActivityPtr activity) { QString html = activity->get_html_render(render_info); emit itemProcessed(html, activity); } diff --git a/src/widgets/status_info.h b/src/widgets/status_info.h index 988f930..5eea7d0 100644 --- a/src/widgets/status_info.h +++ b/src/widgets/status_info.h @@ -12,11 +12,11 @@ class StatusInfoWidgetWorker : public QObject { public slots: void process_item(StatusListItem* item); - void process_activity(APActivity* activity); + void process_activity(APActivityPtr activity); void set_text_zone_width(int width) {render_info.text_zone_width = width;} signals: - void itemProcessed(const QString &html, APActivity* activity = nullptr); + void itemProcessed(const QString &html, APActivityPtr activity = nullptr); private: QLocale locale_context; @@ -38,12 +38,12 @@ public: public slots: void show_list_item(StatusListItem* status); // Call from GUI thread - void postProcess(const QString &html, APActivity* activity); + void postProcess(const QString &html, APActivityPtr activity); signals: // These signals are called privetely by StatusInfoWidget void do_process_item(StatusListItem* item); - void do_process_activity(APActivity* activity); + void do_process_activity(APActivityPtr activity); private: Ui::StatusInfo* ui; @@ -52,5 +52,5 @@ private: // Used for determining if we are dealing with a new list item or not StatusListItem* displayed_item = nullptr; - APActivity* displayed_activity = nullptr; + APActivityPtr displayed_activity; }; diff --git a/src/widgets/tab_activity_list.cpp b/src/widgets/tab_activity_list.cpp index bd396c5..1254315 100644 --- a/src/widgets/tab_activity_list.cpp +++ b/src/widgets/tab_activity_list.cpp @@ -1,5 +1,6 @@ #include "tab_activity_list.h" #include "./ui_tab_activity_list.h" +#include "src/activitypub/apactivity.h" #include "status_info.h" #include "src/net/instance.h" @@ -91,13 +92,12 @@ void TabActivityList::actionOpen_URL_triggered(bool checked) { // TODO: Reuse the Instance object // Really hacky code but works as a PoC and allows testing if (ok and not url.isEmpty()) { - Instance* instance = Instance::create_instance(); + InstancePtr instance = Instance::create_instance(); if (instance) { - APPost* post = instance->get_post_from_url(url); + APPostPtr post = instance->get_post_from_url(url); // Activity will be freed by StatusInfoWidget - APActivity* activity = new APActivity({.object = post}); + auto activity = std::make_shared<APActivity>(APActivityFields {.object = post}); status_info_widget->do_process_activity(activity); - delete instance; instance = nullptr; } else // Best is to remove option from menu, should be douable if the preprocessor touches .ui files QMessageBox::critical(this, tr("Open status from URL"), tr("Could not create Instance object.\nPerhaps network support was disabled at compile time?")); diff --git a/src/widgets/tab_actor_info.cpp b/src/widgets/tab_actor_info.cpp index c769297..9a289e0 100644 --- a/src/widgets/tab_actor_info.cpp +++ b/src/widgets/tab_actor_info.cpp @@ -26,7 +26,6 @@ TabActorInfo::TabActorInfo(Archive* archive, QWidget* parent) } TabActorInfo::~TabActorInfo() { - if (actor) delete actor; delete ui; } diff --git a/src/widgets/tab_actor_info.h b/src/widgets/tab_actor_info.h index c6a4b88..1ec9ca4 100644 --- a/src/widgets/tab_actor_info.h +++ b/src/widgets/tab_actor_info.h @@ -25,5 +25,5 @@ private: void paintEvent(QPaintEvent* event); - APActor* actor = nullptr; + APActorPtr actor; }; |