Put setting loading in a slot so it can be used at startup and when
preferences change
This commit is contained in:
		
					parent
					
						
							
								929a099760
							
						
					
				
			
			
				commit
				
					
						1b9c0adaa8
					
				
			
		
					 2 changed files with 33 additions and 22 deletions
				
			
		| 
						 | 
				
			
			@ -68,6 +68,8 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
 | 
			
		|||
    qmlRegisterType<Danbooru::DanbooruService>("DanbooruClient", 1, 0, "DanbooruService");
 | 
			
		||||
    qRegisterMetaType<DanbooruPost::Rating>();
 | 
			
		||||
 | 
			
		||||
    loadSettings();
 | 
			
		||||
 | 
			
		||||
    // TODO Configurable
 | 
			
		||||
    m_cache = new KImageCache(qApp->applicationName(), DanbooruSettings::self()->cacheSize());
 | 
			
		||||
    m_service->setImageCache(m_cache);
 | 
			
		||||
| 
						 | 
				
			
			@ -129,6 +131,17 @@ DanbooruMainWindow::~DanbooruMainWindow()
 | 
			
		|||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void DanbooruMainWindow::loadSettings()
 | 
			
		||||
{
 | 
			
		||||
    m_service->setBlacklist(DanbooruSettings::self()->tagBlacklist());
 | 
			
		||||
    m_service->setMaxPosts(DanbooruSettings::self()->maxPosts());
 | 
			
		||||
 | 
			
		||||
    m_service->setMaximumAllowedRating(ratingMap.value(DanbooruSettings::self()->maxRating()));
 | 
			
		||||
 | 
			
		||||
    m_service->setMaxPosts(DanbooruSettings::self()->maxPosts());
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void DanbooruMainWindow::setupActions()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -174,7 +187,7 @@ void DanbooruMainWindow::downloadPosts()
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO Pick from configuration
 | 
			
		||||
    m_service->getPostList(1, QStringList(), 10);
 | 
			
		||||
    m_service->getPostList();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -185,15 +198,7 @@ void DanbooruMainWindow::optionsPreferences()
 | 
			
		|||
 | 
			
		||||
    dialog->addPage(new GeneralPage(DanbooruSettings::self(), this), i18n("General"),
 | 
			
		||||
        "table");
 | 
			
		||||
    connect(dialog, &KConfigDialog::settingsChanged, [this](){
 | 
			
		||||
        auto preferences = DanbooruSettings::self();
 | 
			
		||||
        qDebug() << preferences->boards();
 | 
			
		||||
        qDebug() << preferences->cacheSize();
 | 
			
		||||
        qDebug() << preferences->maxPosts();
 | 
			
		||||
        qDebug() << preferences->tagBlacklist();
 | 
			
		||||
        qDebug() << preferences->maxRating();
 | 
			
		||||
        m_service->setMaximumAllowedRating(ratingMap.value(preferences->maxRating()));
 | 
			
		||||
    });
 | 
			
		||||
    connect(dialog, &KConfigDialog::settingsChanged, this, &DanbooruMainWindow::loadSettings);
 | 
			
		||||
    dialog->show();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -50,6 +50,15 @@ class DanbooruConnectWidget;
 | 
			
		|||
class DanbooruMainWindow : public KXmlGuiWindow
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    QQuickWidget *m_view;
 | 
			
		||||
    DanbooruPostModel *m_model;
 | 
			
		||||
    DanbooruService *m_service;
 | 
			
		||||
    DanbooruConnectWidget *m_connectWidget;
 | 
			
		||||
    KImageCache *m_cache;
 | 
			
		||||
    static QHash<int, DanbooruPost::Rating> ratingMap;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    /**
 | 
			
		||||
     * Default Constructor
 | 
			
		||||
| 
						 | 
				
			
			@ -61,22 +70,19 @@ public:
 | 
			
		|||
     */
 | 
			
		||||
    virtual ~DanbooruMainWindow();
 | 
			
		||||
 | 
			
		||||
private Q_SLOTS:
 | 
			
		||||
    void connectToBoard();
 | 
			
		||||
    void downloadPosts();
 | 
			
		||||
    void optionsPreferences();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    void setupActions();
 | 
			
		||||
    void setupConnections();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    QQuickWidget *m_view;
 | 
			
		||||
    DanbooruPostModel *m_model;
 | 
			
		||||
    DanbooruService *m_service;
 | 
			
		||||
    DanbooruConnectWidget *m_connectWidget;
 | 
			
		||||
    KImageCache *m_cache;
 | 
			
		||||
    static QHash<int, DanbooruPost::Rating> ratingMap;
 | 
			
		||||
private Q_SLOTS:
 | 
			
		||||
    void connectToBoard();
 | 
			
		||||
    void downloadPosts();
 | 
			
		||||
    void optionsPreferences();
 | 
			
		||||
    void loadSettings();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
} // namespace Danbooru
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue