Skip to content

Commit bb323b8

Browse files
committed
App: opens links
[skip ci]
1 parent 6d5a716 commit bb323b8

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

‎scripts/gdrive_app.py‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
import os
33
import subprocess
4+
import webbrowser
45
from typing import List, Dict, Any, Optional
56
from dataclasses import dataclass
67

@@ -387,12 +388,16 @@ def on_item_activated(self, item: QListWidgetItem):
387388
self.load_folder(file_data['id'], file_data['name'], clicked_item_id=file_data['id'])
388389
elif mime == 'application/vnd.google-apps.shortcut':
389390
if file_data['shortcutDetails']['targetMimeType'] == 'application/vnd.google-apps.folder':
390-
target_folder = gcache.get_item(file_data['shortcutDetails']['targetId'])
391+
folder_id = file_data['shortcutDetails']['targetId']
391392
target_file = None
392393
else:
393394
target_file = gcache.get_item(file_data['shortcutDetails']['targetId'])
394-
target_folder = gcache.get_item(target_file['parent_id'])
395+
folder_id = target_file['parent_id']
395396
target_file = target_file['id']
397+
target_folder = gcache.get_item(folder_id)
398+
if not target_folder:
399+
url = gdrive_base.FOLDER_LINK.format(folder_id)
400+
webbrowser.open(url)
396401
self.load_folder(target_folder['id'], target_folder['name'], highlight_fileid=target_file, clicked_item_id=file_data['id'])
397402
else:
398403
self.open_file(file_data)
@@ -410,10 +415,8 @@ def open_file(self, file_data: Dict[str, Any]):
410415
else:
411416
os.startfile(str(cache_path))
412417
else:
413-
# Placeholder for download
414-
from PySide6.QtWidgets import QMessageBox
415-
QMessageBox.information(self, "Not in Cache",
416-
f"'{file_data.get('name')}' is not downloaded yet.\nDownloading will be implemented later.")
418+
url = gdrive_base.GENERIC_LINK_PREFIX + file_data['id']
419+
webbrowser.open(url)
417420

418421
def keyPressEvent(self, event):
419422
if event.key() == Qt.Key_Backspace:

‎scripts/gdrive_base.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949

5050
FOLDER_LINK_PREFIX = "https://drive.google.com/drive/folders/"
51+
GENERIC_LINK_PREFIX = "https://drive.google.com/open?id="
5152
FOLDER_LINK = FOLDER_LINK_PREFIX+"{}"
5253
DRIVE_LINK = 'https://drive.google.com/file/d/{}/view?usp=drivesdk'
5354
DOC_LINK = 'https://docs.google.com/document/d/{}/edit?usp=drivesdk'
@@ -80,8 +81,8 @@ def link_to_id(link):
8081
ret = folderlink_to_id(link)
8182
if ret:
8283
return ret
83-
if link.startswith("https://drive.google.com/open?id="):
84-
return link[len("https://drive.google.com/open?id="):].split('&')[0]
84+
if link.startswith(GENERIC_LINK_PREFIX):
85+
return link[len(GENERIC_LINK_PREFIX):].split('&')[0]
8586
ret = GFIDREGEX.search(link)
8687
if ret and link.startswith("https://drive.google.com/"):
8788
return ret.groups()[0]

0 commit comments

Comments
 (0)