Skip to content

Commit

Permalink
Add logout UI #17
Browse files Browse the repository at this point in the history
  • Loading branch information
mak448a committed Jun 12, 2024
1 parent 04aa9b9 commit f6a8840
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 42 deletions.
5 changes: 2 additions & 3 deletions project_notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ If you want to package for Windows, run package_windows.py.


# TODOS!
# Todo: Implement differnet indicator for calling vs images

# Todo: Implement different indicator for calling vs images
# Todo: Make app icon instead of my placeholder one
# Todo: Put main window into a different file for organization
# Todo: Emojis (probably get them when you get the guild)
# Todo: Add logout
# Todo: Add auto logout when credentials are bad
32 changes: 21 additions & 11 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,16 @@ def __init__(self, parent=None):
self.setup()

def connect_signal_slots(self):
# Connect buttons to actions
self.ui.pushButton.clicked.connect(self.handle_input)


# Connect menubar actions
self.ui.actionQuit.triggered.connect(sys.exit)
self.ui.actionAbout.triggered.connect(self.about)
self.ui.actionLicenses.triggered.connect(self.display_licenses)
self.ui.actionLogout.triggered.connect(self.logout_account)

# Shortcuts
# Quit
self.quit_shortcut = QShortcut(QKeySequence("Ctrl+Q"), self)
Expand Down Expand Up @@ -257,7 +262,12 @@ def send_typing(self):

if 0 < len(self.ui.lineEdit.text()) < 2:
discord_integration.send_typing(self.channel)


def logout_account(self):
# Remove Discord token from discordauth.txt
os.remove(platformdirs.user_config_dir("QTCord") + "/discordauth.txt")
# Switch back to the first page, the login page.
switcher.setCurrentIndex(switcher.currentIndex() - 1)

def handle_no_internet() -> None:
try:
Expand All @@ -279,7 +289,7 @@ def handle_no_internet() -> None:
app.setDesktopFileName("io.github.mak448a.QTCord")

# Add widget to switch between pages of UI
widget = QtWidgets.QStackedWidget()
switcher = QtWidgets.QStackedWidget()

if os.path.isfile(platformdirs.user_config_dir("QTCord") + "/discordauth.txt"):
with open(platformdirs.user_config_dir("QTCord") + "/discordauth.txt") as f:
Expand All @@ -291,18 +301,18 @@ def handle_no_internet() -> None:
auth = False

win = ChatInterface()
login = LoginUI(widget)

if not auth:
widget.addWidget(login)
login = LoginUI(switcher)

widget.addWidget(win)
switcher.addWidget(login)
switcher.addWidget(win)
if auth:
switcher.setCurrentIndex(switcher.currentIndex() + 1)

# Set window properties
widget.resize(840, 500)
widget.setWindowTitle("QTCord")
switcher.resize(840, 500)
switcher.setWindowTitle("QTCord")
icon_path = os.path.join(current_dir, "assets", "smiley.svg")
widget.setWindowIcon(QIcon(icon_path))
switcher.setWindowIcon(QIcon(icon_path))

widget.show()
switcher.show()
sys.exit(app.exec())
44 changes: 28 additions & 16 deletions src/ui/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
<enum>QFrame::Shape::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
<enum>QFrame::Shadow::Plain</enum>
</property>
<property name="lineWidth">
<number>1</number>
Expand All @@ -36,8 +36,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>544</width>
<height>409</height>
<width>555</width>
<height>408</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
Expand Down Expand Up @@ -111,7 +111,7 @@ li.checked::marker { content: &quot;\2612&quot;; }
<x>0</x>
<y>0</y>
<width>840</width>
<height>23</height>
<height>30</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
Expand All @@ -127,14 +127,21 @@ li.checked::marker { content: &quot;\2612&quot;; }
<addaction name="actionAbout"/>
<addaction name="actionLicenses"/>
</widget>
<widget class="QMenu" name="menuAccount">
<property name="title">
<string>Acco&amp;unt</string>
</property>
<addaction name="actionLogout"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuAccount"/>
<addaction name="menuHelp"/>
</widget>
<widget class="QDockWidget" name="dockWidget">
<property name="minimumSize">
<size>
<width>270</width>
<height>212</height>
<height>221</height>
</size>
</property>
<attribute name="dockWidgetArea">
Expand All @@ -158,15 +165,15 @@ li.checked::marker { content: &quot;\2612&quot;; }
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter</set>
</property>
<widget class="QWidget" name="friends_scrollArea_contents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>228</width>
<height>387</height>
<width>240</width>
<height>381</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2"/>
Expand Down Expand Up @@ -206,8 +213,8 @@ li.checked::marker { content: &quot;\2612&quot;; }
<rect>
<x>0</x>
<y>0</y>
<width>206</width>
<height>337</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5"/>
Expand All @@ -231,8 +238,8 @@ li.checked::marker { content: &quot;\2612&quot;; }
<rect>
<x>0</x>
<y>0</y>
<width>98</width>
<height>28</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8"/>
Expand All @@ -252,17 +259,22 @@ li.checked::marker { content: &quot;\2612&quot;; }
</widget>
<action name="actionAbout">
<property name="text">
<string>About</string>
<string>&amp;About</string>
</property>
</action>
<action name="actionQuit">
<property name="text">
<string>Quit</string>
<string>&amp;Quit</string>
</property>
</action>
<action name="actionLicenses">
<property name="text">
<string>Licenses</string>
<string>&amp;Licenses</string>
</property>
</action>
<action name="actionLogout">
<property name="text">
<string>Logout</string>
</property>
</action>
</widget>
Expand Down
32 changes: 20 additions & 12 deletions src/ui/main_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def setupUi(self, MainWindow):
self.actionQuit.setObjectName(u"actionQuit")
self.actionLicenses = QAction(MainWindow)
self.actionLicenses.setObjectName(u"actionLicenses")
self.actionLogout = QAction(MainWindow)
self.actionLogout.setObjectName(u"actionLogout")
self.centralwidget = QWidget(MainWindow)
self.centralwidget.setObjectName(u"centralwidget")
self.horizontalLayout_4 = QHBoxLayout(self.centralwidget)
Expand All @@ -40,13 +42,13 @@ def setupUi(self, MainWindow):
self.verticalLayout.setObjectName(u"verticalLayout")
self.scrollArea = QScrollArea(self.centralwidget)
self.scrollArea.setObjectName(u"scrollArea")
self.scrollArea.setFrameShape(QFrame.NoFrame)
self.scrollArea.setFrameShadow(QFrame.Plain)
self.scrollArea.setFrameShape(QFrame.Shape.NoFrame)
self.scrollArea.setFrameShadow(QFrame.Shadow.Plain)
self.scrollArea.setLineWidth(1)
self.scrollArea.setWidgetResizable(True)
self.scrollAreaWidgetContents_2 = QWidget()
self.scrollAreaWidgetContents_2.setObjectName(u"scrollAreaWidgetContents_2")
self.scrollAreaWidgetContents_2.setGeometry(QRect(0, 0, 544, 409))
self.scrollAreaWidgetContents_2.setGeometry(QRect(0, 0, 555, 408))
self.gridLayout = QGridLayout(self.scrollAreaWidgetContents_2)
self.gridLayout.setObjectName(u"gridLayout")
self.gridLayout.setContentsMargins(0, 0, 0, 0)
Expand Down Expand Up @@ -83,15 +85,17 @@ def setupUi(self, MainWindow):
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QMenuBar(MainWindow)
self.menubar.setObjectName(u"menubar")
self.menubar.setGeometry(QRect(0, 0, 840, 23))
self.menubar.setGeometry(QRect(0, 0, 840, 30))
self.menuFile = QMenu(self.menubar)
self.menuFile.setObjectName(u"menuFile")
self.menuHelp = QMenu(self.menubar)
self.menuHelp.setObjectName(u"menuHelp")
self.menuAccount = QMenu(self.menubar)
self.menuAccount.setObjectName(u"menuAccount")
MainWindow.setMenuBar(self.menubar)
self.dockWidget = QDockWidget(MainWindow)
self.dockWidget.setObjectName(u"dockWidget")
self.dockWidget.setMinimumSize(QSize(270, 212))
self.dockWidget.setMinimumSize(QSize(270, 221))
self.dockWidgetContents = QWidget()
self.dockWidgetContents.setObjectName(u"dockWidgetContents")
self.verticalLayout_3 = QVBoxLayout(self.dockWidgetContents)
Expand All @@ -105,10 +109,10 @@ def setupUi(self, MainWindow):
self.scrollArea_2 = QScrollArea(self.friends_tab)
self.scrollArea_2.setObjectName(u"scrollArea_2")
self.scrollArea_2.setWidgetResizable(True)
self.scrollArea_2.setAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignVCenter)
self.scrollArea_2.setAlignment(Qt.AlignmentFlag.AlignLeading|Qt.AlignmentFlag.AlignLeft|Qt.AlignmentFlag.AlignVCenter)
self.friends_scrollArea_contents = QWidget()
self.friends_scrollArea_contents.setObjectName(u"friends_scrollArea_contents")
self.friends_scrollArea_contents.setGeometry(QRect(0, 0, 228, 387))
self.friends_scrollArea_contents.setGeometry(QRect(0, 0, 240, 381))
self.verticalLayout_2 = QVBoxLayout(self.friends_scrollArea_contents)
self.verticalLayout_2.setObjectName(u"verticalLayout_2")
self.scrollArea_2.setWidget(self.friends_scrollArea_contents)
Expand All @@ -132,7 +136,7 @@ def setupUi(self, MainWindow):
self.scrollArea_3.setWidgetResizable(True)
self.servers_scrollArea_contents = QWidget()
self.servers_scrollArea_contents.setObjectName(u"servers_scrollArea_contents")
self.servers_scrollArea_contents.setGeometry(QRect(0, 0, 206, 337))
self.servers_scrollArea_contents.setGeometry(QRect(0, 0, 100, 30))
self.verticalLayout_5 = QVBoxLayout(self.servers_scrollArea_contents)
self.verticalLayout_5.setObjectName(u"verticalLayout_5")
self.scrollArea_3.setWidget(self.servers_scrollArea_contents)
Expand All @@ -149,7 +153,7 @@ def setupUi(self, MainWindow):
self.channels_scrollArea.setWidgetResizable(True)
self.channels_scrollArea_contents = QWidget()
self.channels_scrollArea_contents.setObjectName(u"channels_scrollArea_contents")
self.channels_scrollArea_contents.setGeometry(QRect(0, 0, 98, 28))
self.channels_scrollArea_contents.setGeometry(QRect(0, 0, 100, 30))
self.verticalLayout_8 = QVBoxLayout(self.channels_scrollArea_contents)
self.verticalLayout_8.setObjectName(u"verticalLayout_8")
self.channels_scrollArea.setWidget(self.channels_scrollArea_contents)
Expand All @@ -168,10 +172,12 @@ def setupUi(self, MainWindow):
MainWindow.addDockWidget(Qt.DockWidgetArea.LeftDockWidgetArea, self.dockWidget)

self.menubar.addAction(self.menuFile.menuAction())
self.menubar.addAction(self.menuAccount.menuAction())
self.menubar.addAction(self.menuHelp.menuAction())
self.menuFile.addAction(self.actionQuit)
self.menuHelp.addAction(self.actionAbout)
self.menuHelp.addAction(self.actionLicenses)
self.menuAccount.addAction(self.actionLogout)

self.retranslateUi(MainWindow)

Expand All @@ -184,9 +190,10 @@ def setupUi(self, MainWindow):

def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"QTCord", None))
self.actionAbout.setText(QCoreApplication.translate("MainWindow", u"About", None))
self.actionQuit.setText(QCoreApplication.translate("MainWindow", u"Quit", None))
self.actionLicenses.setText(QCoreApplication.translate("MainWindow", u"Licenses", None))
self.actionAbout.setText(QCoreApplication.translate("MainWindow", u"&About", None))
self.actionQuit.setText(QCoreApplication.translate("MainWindow", u"&Quit", None))
self.actionLicenses.setText(QCoreApplication.translate("MainWindow", u"&Licenses", None))
self.actionLogout.setText(QCoreApplication.translate("MainWindow", u"Logout", None))
self.textBrowser.setHtml(QCoreApplication.translate("MainWindow", u"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http:https://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><meta charset=\"utf-8\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
Expand All @@ -198,6 +205,7 @@ def retranslateUi(self, MainWindow):
self.pushButton.setText(QCoreApplication.translate("MainWindow", u"Send", None))
self.menuFile.setTitle(QCoreApplication.translate("MainWindow", u"&File", None))
self.menuHelp.setTitle(QCoreApplication.translate("MainWindow", u"&Help", None))
self.menuAccount.setTitle(QCoreApplication.translate("MainWindow", u"Acco&unt", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.friends_tab), QCoreApplication.translate("MainWindow", u"Friends", None))
self.servers_notebook.setTabText(self.servers_notebook.indexOf(self.servers), QCoreApplication.translate("MainWindow", u"Servers", None))
self.servers_notebook.setTabText(self.servers_notebook.indexOf(self.channels), QCoreApplication.translate("MainWindow", u"Channels", None))
Expand Down

0 comments on commit f6a8840

Please sign in to comment.