mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Cloud storage: first stab at implementing cloud storage
So far there is no mechanism to actually create a repository on the server, so this only works with the two test repositories. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
a6b6674780
commit
5bbcc7f16d
5 changed files with 98 additions and 4 deletions
19
git-access.c
19
git-access.c
|
@ -87,7 +87,7 @@ int credential_https_cb(git_cred **out,
|
|||
unsigned int allowed_types,
|
||||
void *payload)
|
||||
{
|
||||
const char *username = "ssrftest";
|
||||
const char *username = prefs.cloud_storage_email_encoded;
|
||||
const char *password = prefs.cloud_storage_password ? strdup(prefs.cloud_storage_password) : strdup("");
|
||||
return git_cred_userpass_plaintext_new(out, username, password);
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ static struct git_repository *get_remote_repo(const char *localdir, const char *
|
|||
* https://host/repo[branch]
|
||||
* file://repo[branch]
|
||||
*/
|
||||
static struct git_repository *is_remote_git_repository(const char *remote, const char *branch)
|
||||
static struct git_repository *is_remote_git_repository(char *remote, const char *branch)
|
||||
{
|
||||
char c, *localdir;
|
||||
const char *p = remote;
|
||||
|
@ -241,6 +241,21 @@ static struct git_repository *is_remote_git_repository(const char *remote, const
|
|||
* caches will sadly force that to split into multiple
|
||||
* individual repositories.
|
||||
*/
|
||||
|
||||
/*
|
||||
* next we need to make sure that any encoded username
|
||||
* has been extracted from an https:// based URL
|
||||
*/
|
||||
if (!strncmp(remote, "https://", 8)) {
|
||||
char *at = strchr(remote, '@');
|
||||
if (at) {
|
||||
/* grab the part between "https://" and "@" as encoded email address
|
||||
* (that's our username) and move the rest of the URL forward, remembering
|
||||
* to copy the closing NUL as well */
|
||||
prefs.cloud_storage_email_encoded = strndup(remote + 8, at - remote - 8);
|
||||
memmove(remote + 8, at + 1, strlen(at + 1) + 1);
|
||||
}
|
||||
}
|
||||
localdir = get_local_dir(remote, branch);
|
||||
if (!localdir)
|
||||
return NULL;
|
||||
|
|
1
pref.h
1
pref.h
|
@ -92,6 +92,7 @@ struct preferences {
|
|||
facebook_prefs_t facebook;
|
||||
char *cloud_storage_password;
|
||||
char *cloud_storage_email;
|
||||
char *cloud_storage_email_encoded;
|
||||
bool save_password_local;
|
||||
};
|
||||
enum unit_system_values {
|
||||
|
|
|
@ -305,6 +305,70 @@ void MainWindow::on_actionSaveAs_triggered()
|
|||
file_save_as();
|
||||
}
|
||||
|
||||
static int getCloudURL(QString &filename)
|
||||
{
|
||||
QString email = QString(prefs.cloud_storage_email);
|
||||
email.replace("@", "_at_");
|
||||
email.replace(QRegularExpression("[^a-zA-Z0-9._+-]"), "");
|
||||
if (email.isEmpty() || same_string(prefs.cloud_storage_password, ""))
|
||||
return report_error("Please configure Cloud storage email and password in the preferences");
|
||||
if (email != prefs.cloud_storage_email_encoded) {
|
||||
free(prefs.cloud_storage_email_encoded);
|
||||
prefs.cloud_storage_email_encoded = strdup(qPrintable(email));
|
||||
}
|
||||
filename = QString("https://cloud.subsurface-divelog.org/git/%1[%1]").arg(email);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MainWindow::on_actionCloudstorageopen_triggered()
|
||||
{
|
||||
if (!okToClose(tr("Please save or cancel the current dive edit before opening a new file.")))
|
||||
return;
|
||||
|
||||
QString filename;
|
||||
if (getCloudURL(filename)) {
|
||||
getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error);
|
||||
return;
|
||||
}
|
||||
qDebug() << filename;
|
||||
|
||||
closeCurrentFile();
|
||||
|
||||
int error;
|
||||
|
||||
QByteArray fileNamePtr = QFile::encodeName(filename);
|
||||
error = parse_file(fileNamePtr.data());
|
||||
if (!error) {
|
||||
set_filename(fileNamePtr.data(), true);
|
||||
setTitle(MWTF_FILENAME);
|
||||
}
|
||||
getNotificationWidget()->hideNotification();
|
||||
process_dives(false, false);
|
||||
refreshDisplay();
|
||||
ui.actionAutoGroup->setChecked(autogroup);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionCloudstoragesave_triggered()
|
||||
{
|
||||
QString filename;
|
||||
if (getCloudURL(filename)) {
|
||||
getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error);
|
||||
return;
|
||||
}
|
||||
qDebug() << filename;
|
||||
if (information()->isEditing())
|
||||
information()->acceptChanges();
|
||||
|
||||
if (save_dives(filename.toUtf8().data())) {
|
||||
getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error);
|
||||
return;
|
||||
}
|
||||
getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error);
|
||||
set_filename(filename.toUtf8().data(), true);
|
||||
setTitle(MWTF_FILENAME);
|
||||
mark_divelist_changed(false);
|
||||
}
|
||||
|
||||
void learnImageDirs(QStringList dirnames)
|
||||
{
|
||||
QList<QFuture<void> > futures;
|
||||
|
|
|
@ -103,6 +103,8 @@ slots:
|
|||
void on_actionSave_triggered();
|
||||
void on_actionSaveAs_triggered();
|
||||
void on_actionClose_triggered();
|
||||
void on_actionCloudstorageopen_triggered();
|
||||
void on_actionCloudstoragesave_triggered();
|
||||
void on_actionPrint_triggered();
|
||||
void on_actionPreferences_triggered();
|
||||
void on_actionQuit_triggered();
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>861</width>
|
||||
<height>22</height>
|
||||
<height>29</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
|
@ -74,6 +74,9 @@
|
|||
<addaction name="actionSave"/>
|
||||
<addaction name="actionSaveAs"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionCloudstorageopen"/>
|
||||
<addaction name="actionCloudstoragesave"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionClose"/>
|
||||
<addaction name="actionExport"/>
|
||||
<addaction name="actionPrint"/>
|
||||
|
@ -81,7 +84,6 @@
|
|||
<addaction name="separator"/>
|
||||
<addaction name="actionHash_images"/>
|
||||
<addaction name="actionConfigure_Dive_Computer"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionRecent1"/>
|
||||
<addaction name="actionRecent2"/>
|
||||
<addaction name="actionRecent3"/>
|
||||
|
@ -714,6 +716,16 @@
|
|||
<string>&Find moved images</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionCloudstorageopen">
|
||||
<property name="text">
|
||||
<string>Cloud storage open</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionCloudstoragesave">
|
||||
<property name="text">
|
||||
<string>Cloud storage save</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
Loading…
Add table
Reference in a new issue