File indexing completed on 2024-05-12 05:44:23

0001 /***************************************************************************
0002  *   Copyright (C) 2005-2009 by Rajko Albrecht  ral@alwins-world.de        *
0003  *   https://kde.org/applications/development/org.kde.kdesvn               *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
0019  ***************************************************************************/
0020 
0021 #include "getinfothread.h"
0022 #include "svnfrontend/models/svnitemnode.h"
0023 #include "svnqt/status.h"
0024 #include "svnqt/url.h"
0025 #include "tcontextlistener.h"
0026 
0027 #include <QMutexLocker>
0028 #include <QReadLocker>
0029 #include <QWriteLocker>
0030 
0031 GetInfoThread::GetInfoThread(QObject *_parent)
0032     : SvnThread(_parent)
0033     , m_NodeQueue()
0034     , m_Cancel(false)
0035     , m_QueueLock()
0036     , m_CancelLock()
0037 {
0038 }
0039 
0040 GetInfoThread::~GetInfoThread()
0041 {
0042 }
0043 
0044 void GetInfoThread::run()
0045 {
0046     svn::InfoEntry info;
0047     svn::Revision rev = svn::Revision::UNDEFINED;
0048     try {
0049         while (true) {
0050             {
0051                 QReadLocker cl(&m_CancelLock);
0052                 if (m_Cancel) {
0053                     break;
0054                 }
0055             }
0056             SvnItemModelNode *current = nullptr;
0057             {
0058                 QMutexLocker ml(&m_QueueLock);
0059                 if (!m_NodeQueue.isEmpty()) {
0060                     current = m_NodeQueue.dequeue();
0061                 }
0062             }
0063             if (current) {
0064                 if (!current->hasToolTipText()) {
0065                     if (current->isRealVersioned() && !current->stat()->entry().url().isEmpty()) {
0066                         if (svn::Url::isValid(current->fullName())) {
0067                             rev = current->revision();
0068                         } else {
0069                             rev = svn::Revision::UNDEFINED;
0070                         }
0071                         itemInfo(current->fullName(), info, rev, current->correctPeg());
0072                     }
0073                     current->generateToolTip(info);
0074                 }
0075             } else {
0076                 break;
0077             }
0078         }
0079     } catch (const svn::Exception &e) {
0080         m_SvnContextListener->contextNotify(e.msg());
0081     }
0082 }
0083 
0084 void GetInfoThread::cancelMe()
0085 {
0086     SvnThread::cancelMe();
0087     {
0088         QWriteLocker cl(&m_CancelLock);
0089         m_Cancel = true;
0090     }
0091 }
0092 
0093 void GetInfoThread::appendNode(SvnItemModelNode *node)
0094 {
0095     if (!node) {
0096         return;
0097     }
0098     QMutexLocker ml(&m_QueueLock);
0099     bool found = false;
0100     for (const SvnItemModelNode *qNode : qAsConst(m_NodeQueue)) {
0101         if (qNode->fullName() == node->fullName()) {
0102             found = true;
0103             break;
0104         }
0105     }
0106     if (!found) {
0107         m_NodeQueue.enqueue(node);
0108     }
0109     m_SvnContextListener->setCanceled(false);
0110     if (!isRunning()) {
0111         {
0112             QWriteLocker cl(&m_CancelLock);
0113             m_Cancel = false;
0114         }
0115         start();
0116     }
0117 }
0118 
0119 void GetInfoThread::clearNodes()
0120 {
0121     QMutexLocker ml(&m_QueueLock);
0122     m_NodeQueue.clear();
0123 }
0124 
0125 #include "moc_getinfothread.cpp"