File indexing completed on 2024-05-12 05:21:25

0001 /*
0002   This file is part of KOrganizer.
0003 
0004   SPDX-FileCopyrightText: 2000, 2003 Cornelius Schumacher <schumacher@kde.org>
0005 
0006   SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
0007 */
0008 
0009 #include "kowindowlist.h"
0010 #include "mainwindow.h"
0011 
0012 #include <QUrl>
0013 
0014 KOWindowList::KOWindowList()
0015     : QObject(nullptr)
0016 {
0017 }
0018 
0019 KOWindowList::~KOWindowList() = default;
0020 
0021 void KOWindowList::addWindow(KOrg::MainWindow *korg)
0022 {
0023     if (!korg->hasDocument()) {
0024         mDefaultWindow = korg;
0025     } else {
0026         mWindowList.append(korg);
0027     }
0028 }
0029 
0030 void KOWindowList::removeWindow(KOrg::MainWindow *korg)
0031 {
0032     if (korg == mDefaultWindow) {
0033         mDefaultWindow = nullptr;
0034     } else {
0035         mWindowList.removeAll(korg);
0036     }
0037 }
0038 
0039 bool KOWindowList::lastInstance()
0040 {
0041     const int countWindow = mWindowList.count();
0042     if (countWindow == 1 && !mDefaultWindow) {
0043         return true;
0044     }
0045 
0046     if (countWindow == 0 && mDefaultWindow) {
0047         return true;
0048     } else {
0049         return false;
0050     }
0051 }
0052 
0053 KOrg::MainWindow *KOWindowList::findInstance(const QUrl &url)
0054 {
0055     for (KOrg::MainWindow *inst : std::as_const(mWindowList)) {
0056         if (inst && inst->getCurrentURL() == url) {
0057             return inst;
0058         }
0059     }
0060     return nullptr;
0061 }
0062 
0063 KOrg::MainWindow *KOWindowList::defaultInstance()
0064 {
0065     return mDefaultWindow;
0066 }
0067 
0068 #include "moc_kowindowlist.cpp"