33from kivy .lang import Builder
44from kivy .core .clipboard import Clipboard
55from kivy .metrics import dp
6- #from kivymd.toast import toast
76
87from kivymd .uix .snackbar import (
98 MDSnackbar ,
109 MDSnackbarSupportingText ,
1110 MDSnackbarText ,
1211)
12+
1313from kivymd .uix .list import (
1414 MDListItem ,
1515 MDListItemHeadlineText ,
1616 MDListItemLeadingIcon )
1717
18+
19+ from kivy .lang import Builder
20+ from kivy .uix .widget import Widget
21+
22+ from kivymd .app import MDApp
23+ from kivymd .uix .button import MDButton , MDButtonText
24+ from kivymd .uix .dialog import (
25+ MDDialog ,
26+ MDDialogIcon ,
27+ MDDialogHeadlineText ,
28+ MDDialogSupportingText ,
29+ MDDialogButtonContainer ,
30+ MDDialogContentContainer ,
31+ )
32+
33+
34+ from kivymd .uix .dialog import (
35+ MDDialog ,
36+ MDDialogIcon ,
37+ MDDialogHeadlineText ,
38+ MDDialogSupportingText ,
39+ MDDialogButtonContainer ,
40+ MDDialogContentContainer ,
41+ )
42+
43+ from kivymd .uix .divider import MDDivider
44+ from kivymd .uix .list import (
45+ MDListItem ,
46+ MDListItemLeadingIcon ,
47+ MDListItemSupportingText ,
48+ )
49+
1850from kivymd .uix .filemanager import MDFileManager
1951from kivymd .uix .button import MDIconButton
2052
21-
2253import webbrowser
2354import json
2455import os
@@ -72,6 +103,44 @@ def list_cb_b():
72103 list_lb = json .load (f )
73104 return list_lb
74105
106+ # Internet connection
107+ def ping ():
108+
109+ # Show dialog when there is an connection problem
110+ def dialog (message ):
111+ dialog = MDDialog (
112+ MDDialogIcon (icon = "alert" ,),
113+ MDDialogHeadlineText (text = "Attention!" ,),
114+ MDDialogSupportingText (text = message ,),
115+ )
116+ dialog .open ()
117+
118+ # Check connection and availability of Catbox
119+ def check (url , message ):
120+
121+ try :
122+ response = requests .get (url , timeout = 5 )
123+ if response .ok :
124+ print (f'{ url } pong' )
125+ return True
126+ else :
127+ raise requests .exceptions .RequestException ()
128+ except requests .exceptions .RequestException :
129+ print (f'No connection or responce issue with { url } ' )
130+ dialog (message )
131+ return False
132+
133+ # Check if user have internet connection (by google becasue it's available all time)
134+ if check ("https://www.google.com" ,
135+ "It looks like you have connection issues! The main functions of the app will not work!" ):
136+
137+ # Check if Catbox is available after knowing that the user is online
138+ # Don't check Litterbox because it has the domain of Catbox
139+ if check ("https://catbox.moe" ,
140+ "It looks like Catbox is not available now! The main functions of the app will not work!" ):
141+
142+ print ("All systems go" )
143+
75144
76145
77146## === App === ##
@@ -107,6 +176,7 @@ def on_start(self):
107176 self .title = "CatBox Client" # App title
108177 self .add_lb ()
109178 self .add_cb_a ()
179+ ping ()
110180
111181
112182
@@ -179,7 +249,7 @@ def events(self, instance, keyboard, keycode, text, modifiers):
179249 def link (self , option ):
180250 link = option
181251 Clipboard .copy (link )
182- #toast("Link copied to the clipboard")
252+
183253 print ("Link copied to the clipboard" )
184254
185255
@@ -395,14 +465,37 @@ def upload_cb(self):
395465 if file_cb == "" :
396466 return
397467 else :
398-
399468 if method == "anon" :
400469 result = self .upl_anon ()
401470 print ("Anon uploaded file:" , result )
471+
472+ notification = MDSnackbar (
473+ MDSnackbarSupportingText (
474+ text = f"Catbox uploaded file (anon): { result } " ,
475+ ),
476+ y = dp (10 ),
477+ orientation = "horizontal" ,
478+ pos_hint = {"center_x" : 0.5 },
479+ size_hint_x = 0.8 ,
480+ )
481+ notification .open ()
482+
402483 self .add_list_cb_a (result )
403484 else :
404485 result = self .upl_auth ()
405486 print ("Auth uploaded file:" , result )
487+
488+ notification = MDSnackbar (
489+ MDSnackbarSupportingText (
490+ text = f"Catbox uploaded file (auth): { result } " ,
491+ ),
492+ y = dp (10 ),
493+ orientation = "horizontal" ,
494+ pos_hint = {"center_x" : 0.5 },
495+ size_hint_x = 0.8 ,
496+ )
497+ notification .open ()
498+
406499 self .add_list_cb_b (result )
407500
408501
@@ -415,6 +508,18 @@ def call_upload_lb(self):
415508 else :
416509 result = self .upl_lb ()
417510 print ("Litterbox uploaded file:" , result )
511+
512+ notification = MDSnackbar (
513+ MDSnackbarSupportingText (
514+ text = f"Litterbox uploaded file: { result } " ,
515+ ),
516+ y = dp (10 ),
517+ orientation = "horizontal" ,
518+ pos_hint = {"center_x" : 0.5 },
519+ size_hint_x = 0.8 ,
520+ )
521+ notification .open ()
522+
418523 self .add_list_lb (result )
419524 self .add_lb ()
420525
@@ -446,14 +551,46 @@ def remove_cb_a(self, option):
446551 del datalist [to_remove ]
447552 else :
448553 print (f"Name { to_remove } not found!" )
554+ return
449555
450556 with open ('list_cb_a.json' , 'w' , encoding = 'utf-8' ) as file :
451557 json .dump (datalist , file , ensure_ascii = False , indent = 4 )
558+
452559
453560 self .add_cb_b ()
454561 self .add_cb_a ()
455562
456563
564+
565+
566+ # Remove CB-b (json)
567+ def remove_cb_b_list (self , option ):
568+ datalist = list_cb_b ()
569+ to_remove = option
570+
571+ # Remove from .json
572+ if to_remove in datalist :
573+ del datalist [to_remove ]
574+ else :
575+ print (f"Name { to_remove } not found!" )
576+
577+ with open ('list_cb_b.json' , 'w' , encoding = 'utf-8' ) as file :
578+ json .dump (datalist , file , ensure_ascii = False , indent = 4 )
579+
580+ notification = MDSnackbar (
581+ MDSnackbarText (text = "Success" ),
582+ MDSnackbarSupportingText (text = "File was deleted from Catbox" ),
583+ y = dp (10 ),
584+ orientation = "horizontal" ,
585+ pos_hint = {"center_x" : 0.5 },
586+ size_hint_x = 0.8 ,
587+ )
588+ notification .open ()
589+
590+ self .add_cb_a ()
591+ self .add_cb_b ()
592+
593+
457594 # Remove CB-b
458595 def remove_cb_b (self , option ):
459596 global cbb_items
@@ -465,6 +602,18 @@ def remove_cb_b(self, option):
465602 userhash = settings ['userhash' ]
466603 url = "https://catbox.moe/user/api.php"
467604
605+ def show_error ():
606+ message = "Could not delete file from Catbox. Check your userhash or try later."
607+ notification = MDSnackbar (
608+ MDSnackbarText (text = "Error" ),
609+ MDSnackbarSupportingText (text = message ),
610+ y = dp (10 ),
611+ orientation = "horizontal" ,
612+ pos_hint = {"center_x" : 0.5 },
613+ size_hint_x = 0.8 ,
614+ )
615+ notification .open ()
616+
468617 if to_remove in datalist :
469618 link = datalist [to_remove ]["link" ]
470619 print (link )
@@ -484,25 +633,16 @@ def remove_cb_b(self, option):
484633
485634 response = requests .post (url , data = data )
486635
487- # Remove from .json
488- if to_remove in datalist :
489- del datalist [to_remove ]
490- else :
491- print (f"Name { to_remove } not found!" )
492-
493- with open ('list_cb_b.json' , 'w' , encoding = 'utf-8' ) as file :
494- json .dump (datalist , file , ensure_ascii = False , indent = 4 )
495-
496- self .add_cb_a ()
497- self .add_cb_b ()
498- print (response )
499636
500637 if response .status_code == 200 :
501638 if "success" in response .text .lower ():
639+ self .remove_cb_b_list (option = to_remove )
502640 return "File was deleted from server"
503641 else :
642+ show_error ()
504643 return f"Error: { response .text } "
505644 else :
645+ show_error ()
506646 return f"Request error. Error code: { response .status_code } "
507647
508648
0 commit comments