1"""
2 @file
3 @brief This file contains the credits treeview, used by the about window
4 @author Noah Figg <eggmunkee@hotmail.com>
5 @author Jonathan Thomas <jonathan@openshot.org>
6
7 @section LICENSE
8
9 Copyright (c) 2008-2018 OpenShot Studios, LLC
10 (http://www.openshotstudios.com). This file is part of
11 OpenShot Video Editor (http://www.openshot.org), an open-source project
12 dedicated to delivering high quality video editing and animation solutions
13 to the world.
14
15 OpenShot Video Editor is free software: you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation, either version 3 of the License, or
18 (at your option) any later version.
19
20 OpenShot Video Editor is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with OpenShot Library.  If not, see <http://www.gnu.org/licenses/>.
27 """
28
29import os
30from urllib.parse import urlparse
31
32import webbrowser
33from PyQt5.QtCore import QSize, Qt, QPoint
34from PyQt5.QtWidgets import QListView, QTreeView, QMessageBox, QAbstractItemView, QMenu, QSizePolicy, QHeaderView, QApplication
35from PyQt5.QtGui import QCursor
36from functools import partial
37
38from classes.logger import log
39from classes.app import get_app
40from windows.models.credits_model import CreditsModel
41
42import json
43
44class CreditsTreeView(QTreeView):
45    """ A ListView QWidget used on the credits window """
46    def resize_contents(self):
47        pass
48
49    def refresh_view(self, filter=None):
50        self.credits_model.update_model(filter=filter)
51
52        # Format columns
53        self.header().setSectionResizeMode(0, QHeaderView.Fixed)
54        self.header().setSectionResizeMode(1, QHeaderView.Fixed)
55        self.setColumnWidth(0, 22)
56        self.setColumnWidth(1, 22)
57        self.setColumnWidth(2, 150)
58        self.setColumnWidth(3, 150)
59        self.setColumnWidth(4, 150)
60        self.sortByColumn(2, Qt.AscendingOrder)
61
62        if "email" not in self.columns:
63            self.setColumnHidden(3, True)
64        if "website" not in self.columns:
65            self.setColumnHidden(4, True)
66
67    def contextMenuEvent(self, event):
68        log.info('contextMenuEvent')
69        _ = get_app()._tr
70
71        # Get data model and selection
72        model = self.credits_model.model
73        row = self.indexAt(event.pos()).row()
74        if row != -1:
75            email = model.item(row, 3).text()
76            website = model.item(row, 4).text()
77
78            menu = QMenu(self)
79            if email:
80                copy_action = menu.addAction(_("Copy E-mail"))
81                copy_action.triggered.connect(partial(self.CopyEmailTriggered, email))
82            if website:
83                github_action = menu.addAction(_("View Website"))
84                github_action.triggered.connect(partial(self.ViewWebsite, website))
85            menu.popup(QCursor.pos())
86
87    def CopyEmailTriggered(self, email=""):
88        log.info("CopyEmailTriggered")
89        clipboard = QApplication.clipboard()
90        clipboard.setText(email)
91
92    def ViewWebsite(self, website=""):
93        log.info("ViewWebsite")
94        try:
95            webbrowser.open(website)
96        except:
97            log.warning('Failed to launch web browser to %s' % website)
98
99    def __init__(self, credits, columns, *args):
100        # Invoke parent init
101        QListView.__init__(self, *args)
102
103        # Get a reference to the window object
104        self.win = get_app().window
105
106        # Get Model data
107        self.credits_model = CreditsModel(credits)
108        self.selected = []
109
110        # Setup header columns
111        self.setModel(self.credits_model.model)
112        self.setIndentation(0)
113        self.setSelectionBehavior(QTreeView.SelectRows)
114        self.setSelectionBehavior(QAbstractItemView.SelectRows)
115        self.setSelectionMode(QAbstractItemView.ExtendedSelection)
116        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
117        self.setWordWrap(True)
118        self.setStyleSheet('QTreeView::item { padding-top: 2px; }')
119        self.columns = columns
120
121
122        # Refresh view
123        self.refresh_view()
124
125        # setup filter events
126        app = get_app()
127