Skip to content

Commit

Permalink
Upload to an existing stream.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinzulen authored and Jinzulen committed Mar 9, 2021
1 parent b2e3c0a commit d86d152
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
32 changes: 25 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def updateUi(self):

self.settingsDialog.group_account.label_password.show()
self.settingsDialog.group_account.input_password.show()

# Hide the upload and clipboard configuration
self.settingsDialog.group_upload.hide()
self.settingsDialog.group_clipboard.hide()

# Inject the default image title into the name field.
self.settingsDialog.group_upload.input_name.setText(self.Format)
Expand All @@ -64,12 +68,13 @@ def loadSettings(self):
self.Username = Settings.value("username", "")
self.Password = Settings.value("password", "")

# Image title
# Image title and stream
self.Stream = Settings.value("stream", "")
self.Format = Settings.value("name-format", "Screenshot at %H-%M-%S")

# Clipboard
self.copyCloudup = Settings.value("copy-cloudup", "true") in ["true", True]
self.copyDirect = Settings.value("copy-direct", "true") in ["true", True]
self.copyCloudup = Settings.value("copy-cloudup", "true") in ["true", True]
self.copyNothing = Settings.value("copy-nothing", "true") in ["true", True]

Settings.endGroup()
Expand All @@ -82,6 +87,9 @@ def showSettingsUI(self, parentWidget):
self.settingsDialog.group_upload.input_name.connect("textChanged(QString)", self.nameFormatEdited)
self.settingsDialog.connect("accepted()", self.saveSettings)

# Inject the upload stream
self.settingsDialog.group_upload.input_stream.text = self.Stream

# Inject default values.
self.loadSettings()

Expand Down Expand Up @@ -110,8 +118,9 @@ def saveSettings(self):
Settings.setValue("username", self.settingsDialog.group_account.input_username.text)
Settings.setValue("password", self.settingsDialog.group_account.input_password.text)

# Image title
# Image title and stream
Settings.setValue("name-format", self.settingsDialog.group_upload.input_name.text)
Settings.setValue("stream", self.settingsDialog.group_upload.input_stream.text)

# Clipboard
Settings.setValue("copy-cloudup", not self.settingsDialog.group_clipboard.radio_cloudup.checked)
Expand All @@ -121,6 +130,9 @@ def saveSettings(self):
Settings.endGroup()
Settings.endGroup()

self.updateUi()
self.settingsDialog.open()

# Login.
def Login(self):
self.saveSettings()
Expand Down Expand Up @@ -182,12 +194,18 @@ def upload(self, screenshot, name):
FilePath = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(time.time()))
screenshot.save(QFile(FilePath), ScreenCloud.getScreenshotFormat())

# Create stream
s = requests.post("https://api.cloudup.com/1/streams?access_token=" + self.Key, data = {"title": name}, headers = Headers)
c = s.json()
# Has a stream been specified or should we create on?
if self.Stream:
Stream = self.Stream
else:
# Create stream
s = requests.post("https://api.cloudup.com/1/streams?access_token=" + self.Key, data = {"title": name}, headers = Headers)
c = s.json()

Stream = c["id"]

# Create item inside the stream
i = requests.post("https://api.cloudup.com/1/items?access_token=" + self.Key, data = {"filename": FilePath, "stream_id": c["id"]}, headers = Headers)
i = requests.post("https://api.cloudup.com/1/items?access_token=" + self.Key, data = {"filename": FilePath, "stream_id": Stream}, headers = Headers)
j = json.loads(i.text)

# Upload
Expand Down
27 changes: 26 additions & 1 deletion settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
</property>
</widget>
</item>

<item row="2" column="1">
<widget class="QLabel" name="label_example">
<property name="text">
Expand All @@ -164,6 +164,31 @@
</item>
</layout>
</item>

<!-- Upload stream -->
<item>
<layout class="QFormLayout" name="formLayout_2">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>

<item row="1" column="0">
<widget class="QLabel" name="label_stream">
<property name="text">
<string>Stream ID:</string>
</property>
</widget>
</item>

<item row="1" column="1">
<widget class="QLineEdit" name="input_stream">
<property name="text">
<string extracomment="Hlap" />
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit d86d152

Please sign in to comment.