File indexing completed on 2025-01-05 05:14:40
0001 /* 0002 SPDX-FileCopyrightText: 2021 Hamed Masafi <hamed.masfi@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "remoteswidget.h" 0008 #include "actions/remotesactions.h" 0009 #include "models/remotesmodel.h" 0010 0011 #include <entities/branch.h> 0012 #include <gitmanager.h> 0013 0014 RemotesWidget::RemotesWidget(Git::Manager *git, AppWindow *parent) 0015 : WidgetBase(git, parent) 0016 { 0017 setupUi(this); 0018 0019 init(git); 0020 } 0021 0022 void RemotesWidget::saveState(QSettings &settings) const 0023 { 0024 save(settings, splitter); 0025 save(settings, treeWidget); 0026 } 0027 0028 void RemotesWidget::restoreState(QSettings &settings) 0029 { 0030 restore(settings, splitter); 0031 restore(settings, treeWidget); 0032 } 0033 0034 void RemotesWidget::slotListViewItemActivated(const QModelIndex &index) 0035 { 0036 auto remote = mModel->fromIndex(index); 0037 if (!remote) 0038 return; 0039 0040 mActions->setRemoteName(remote->name()); 0041 labelRemoteName->setText(remote->name()); 0042 labelFetchUrl->setText(remote->fetchUrl()); 0043 labelPushUrl->setText(remote->pushUrl()); 0044 labelDefaultBranch->setText(remote->defaultBranch()); 0045 treeWidget->clear(); 0046 // for (auto &ref : remote->refSpecList()) { 0047 // auto item = new QTreeWidgetItem(treeWidget); 0048 0049 // item->setText(0, ref->name()); 0050 // item->setText(1, ref->source()); 0051 // item->setText(2, ref->destionation()); 0052 // item->setText(3, ref->direction() == Git::RefSpec::Direction::DirectionFetch ? "Fetch" : "Push"); 0053 0054 // treeWidget->addTopLevelItem(item); 0055 // } 0056 for (const auto &rb : remote->branches()) { 0057 auto item = new QTreeWidgetItem(treeWidget); 0058 0059 item->setText(0, rb->name()); 0060 item->setText(1, rb->refName()); 0061 item->setText(2, rb->upStreamName()); 0062 item->setText(2, rb->isHead() ? i18n("Update") : ""); 0063 0064 treeWidget->addTopLevelItem(item); 0065 } 0066 } 0067 0068 void RemotesWidget::slotListViewCustomContextMenuRequested(const QPoint &pos) 0069 { 0070 Q_UNUSED(pos) 0071 auto remote = mModel->fromIndex(listView->currentIndex()); 0072 if (!remote) 0073 return; 0074 0075 mActions->setRemoteName(remote->name()); 0076 mActions->popup(); 0077 } 0078 0079 void RemotesWidget::init(Git::Manager *git) 0080 { 0081 mModel = git->remotesModel(); 0082 listView->setModelColumn(0); 0083 listView->setModel(mModel); 0084 0085 mActions = new RemotesActions(git, this); 0086 pushButtonAdd->setAction(mActions->actionCreate()); 0087 pushButtonRemove->setAction(mActions->actionRemove()); 0088 0089 connect(listView, &ListView::itemActivated, this, &RemotesWidget::slotListViewItemActivated); 0090 connect(listView, &QListView::customContextMenuRequested, this, &RemotesWidget::slotListViewCustomContextMenuRequested); 0091 } 0092 0093 #include "moc_remoteswidget.cpp"