openvfs-rb 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66a6247ce26a8d5388b5a5b6982958ea408cec169465cf08bb2f1e13145631b7
4
- data.tar.gz: db6e541828e75ac889314d49fda159f32a38c752d3dbab554ea9a56a67a9708f
3
+ metadata.gz: bdbe8e65424e0aede99df961aa92b1f10e5c0ca9b52914e41edcd2e16a7d9c73
4
+ data.tar.gz: d4b3a5050ae7bc62fa838b9d9f8cdee66f8049279fdd6d83f7398ec2e9469b71
5
5
  SHA512:
6
- metadata.gz: a5f1069b92d4e3ed00126fe2da06cebc425cd9ecb3084566940ed177336c4a074d396d4c7ef91591bac55aae6eaf2b6aa2f8d04364ee8ca613ede3d95be96769
7
- data.tar.gz: b55c9d9884575814ac17200e3f78ef60d4eb67b3109ead5ba5acdb0e58697f0da62ddc28f97275285778ef93cbaa219bcde8ea950669af8a65879b4be550c5ab
6
+ metadata.gz: '009b52146424b5f3457bca82a3f1ece15a107786570faf7d76d740477bff3fc1ec6695507ca32da8b62f73f23b0a27243dbc5aabe7147ee4bb3e62d0affe8225'
7
+ data.tar.gz: 59ef29bdeb222209ccef84e7d3a3ab4cb2387f36ec7fb1214cb2554f36db77742851c32f35da6abe6e47c16781bdac9be7cfc3fd0ca8838183f17f1fbb36dbbd
@@ -375,6 +375,11 @@ class ApplicationScope
375
375
  public:
376
376
  ApplicationScope()
377
377
  {
378
+ // Whatever the name is, it is the account's: ConfigFile derives both the config
379
+ // directory and the file inside it from the application name, so losing it would
380
+ // point the engine at a different account's config.
381
+ _name = QCoreApplication::applicationName();
382
+
378
383
  if (QCoreApplication::instance()) {
379
384
  return;
380
385
  }
@@ -383,7 +388,7 @@ public:
383
388
  static char name[] = "openvfs-rb";
384
389
  static char *argv[] = {name, nullptr};
385
390
  _application = std::make_unique<QCoreApplication>(argc, argv);
386
- _application->setApplicationName(QStringLiteral("openvfs-rb"));
391
+ _application->setApplicationName(_name);
387
392
  }
388
393
 
389
394
  ~ApplicationScope()
@@ -394,10 +399,11 @@ public:
394
399
 
395
400
  _application.reset();
396
401
  // QCoreApplication clears the application name when it is destroyed.
397
- QCoreApplication::setApplicationName(QStringLiteral("openvfs-rb"));
402
+ QCoreApplication::setApplicationName(_name);
398
403
  }
399
404
 
400
405
  private:
406
+ QString _name;
401
407
  std::unique_ptr<QCoreApplication> _application;
402
408
  };
403
409
 
@@ -519,6 +525,22 @@ extern "C" void Init_occ()
519
525
  // bootstrap. It takes the arguments the command line already accepts.
520
526
  // -----------------------------------------------------------------------------------------
521
527
 
528
+ // ConfigFile::configPath is QStandardPaths::AppConfigLocation, which is
529
+ // $XDG_CONFIG_HOME/<application name>, and ConfigFile::configFile is that plus the
530
+ // lowercased name and ".cfg". So the name is what picks the config out, and one
531
+ // process per account means setting it per account.
532
+ rb_mOpenVFS.define_module_function("application_name", []() {
533
+ return QCoreApplication::applicationName();
534
+ });
535
+
536
+ rb_mOpenVFS.define_module_function(
537
+ "application_name=",
538
+ [](const QString &name) {
539
+ QCoreApplication::setApplicationName(name);
540
+ return name;
541
+ },
542
+ Arg("name"));
543
+
522
544
  rb_mOpenVFS.define_module_function(
523
545
  "start",
524
546
  [](const QStringList &arguments) {
@@ -636,6 +658,26 @@ extern "C" void Init_occ()
636
658
  .define_attr("estimated_bandwidth", &OCC::ProgressInfo::Estimates::estimatedBandwidth, Rice::AttrAccess::Read)
637
659
  .define_attr("estimated_eta", &OCC::ProgressInfo::Estimates::estimatedEta, Rice::AttrAccess::Read);
638
660
 
661
+ // One file's share of the run. The engine keeps a Progress per file in flight and
662
+ // discards it when the file finishes, so this is what a per-file progress bar reads;
663
+ // ProgressInfo's own totals are the whole run.
664
+ Data_Type<OCC::ProgressInfo::Progress> rb_cProgress =
665
+ define_class_under<OCC::ProgressInfo::Progress>(rb_mOpenVFS, "Progress")
666
+ .define_method("completed", &OCC::ProgressInfo::Progress::completed)
667
+ .define_method("remaining", &OCC::ProgressInfo::Progress::remaining)
668
+ .define_method("estimates", &OCC::ProgressInfo::Progress::estimates);
669
+
670
+ Data_Type<OCC::ProgressInfo::ProgressItem> rb_cProgressItem =
671
+ define_class_under<OCC::ProgressInfo::ProgressItem>(rb_mOpenVFS, "ProgressItem")
672
+ // Both by value, so Ruby owns a copy and may keep it after the signal returns -
673
+ // the engine's own entry goes when the file does.
674
+ .define_method("item", [](const OCC::ProgressInfo::ProgressItem &self) {
675
+ return OCC::SyncFileItemPtr::create(self._item);
676
+ })
677
+ .define_method("progress", [](const OCC::ProgressInfo::ProgressItem &self) {
678
+ return self._progress;
679
+ });
680
+
639
681
  Data_Type<OCC::ProgressInfo> rb_cProgressInfo =
640
682
  define_class_under<OCC::ProgressInfo>(rb_mOpenVFS, "ProgressInfo")
641
683
  .define_method("status", &OCC::ProgressInfo::status)
@@ -652,6 +694,18 @@ extern "C" void Init_occ()
652
694
  .define_method("file_progress", [](const OCC::ProgressInfo &self, const OCC::SyncFileItemPtr &item) {
653
695
  return self.fileProgress(*item);
654
696
  }, Arg("item"))
697
+ // The files in flight, keyed by the path the engine names them by. A Hash rather
698
+ // than the QHash itself: Rice ships no converter for one, and what a caller wants
699
+ // is to look a path up.
700
+ .define_method("current_items", [](const OCC::ProgressInfo &self) {
701
+ Hash items;
702
+
703
+ for (auto entry = self._currentItems.constBegin(); entry != self._currentItems.constEnd(); ++entry) {
704
+ items[entry.key()] = entry.value();
705
+ }
706
+
707
+ return items;
708
+ })
655
709
  .define_method("current_discovered_remote_folder", [](const OCC::ProgressInfo &self) {
656
710
  return self._currentDiscoveredRemoteFolder;
657
711
  })
data/lib/openvfs/occ.rb CHANGED
@@ -12,8 +12,22 @@ end
12
12
 
13
13
  require "fileutils"
14
14
  require "securerandom"
15
+ require "uri"
15
16
 
16
17
  module OpenVFS
18
+ # What the engine calls itself, which is also where it reads its config.
19
+ # @parameter user [String] the user on the server.
20
+ # @parameter url [String] the server's base URL, whose host names the account with the user.
21
+ # @returns [String] the application name for that account.
22
+ def self.application_name_for(user, url) = "#{user}@#{URI(url.to_s).host}"
23
+
24
+ # The INI that application name resolves to, derived the way ConfigFile derives it.
25
+ # @parameter name [String] the application name; the current one by default.
26
+ # @returns [String] the config file for that name.
27
+ def self.config_path(name = application_name)
28
+ File.join(ENV.fetch("XDG_CONFIG_HOME", File.join(Dir.home, ".config")), name, "#{name.downcase}.cfg")
29
+ end
30
+
17
31
  # Writes the INI file AccountManager::restore and FolderMan::loadFolders read on start.
18
32
  #
19
33
  # The credential is not written here: credentials live in the keychain, so store it with Account#credential_manager.set("http/oauthtoken", credential) before starting.
@@ -21,12 +35,16 @@ module OpenVFS
21
35
  # @parameter path [String] The local directory to sync.
22
36
  # @parameter url [String] The server's base URL.
23
37
  # @parameter remote_path [String] The WebDAV path to sync against.
38
+ # @parameter user [String] The user on that server. With the server's host it names the account, which is the application name and so the config file.
24
39
  # @parameter uuid [String] The account's UUID; also names the keychain entry.
25
40
  # @parameter display_name [String] How the folder is named in logs.
26
41
  # @parameter space_id [String] The space to sync, if any.
27
42
  # @returns [String] The UUID the account was written under.
28
- def self.configure(path, url:, remote_path:, uuid: SecureRandom.uuid, display_name: path, space_id: "")
29
- config_path = File.join(Dir.home, ".config", "openvfs-rb", "openvfs-rb.cfg")
43
+ def self.configure(path, url:, remote_path:, user:, uuid: SecureRandom.uuid, display_name: path, space_id: "")
44
+ # One account per process, so the application name is the account's: it is what decides which config the engine reads, and OpenVFS.start reads it rather than being told.
45
+ self.application_name = application_name_for(user, url)
46
+
47
+ config_path = self.config_path
30
48
  FileUtils.mkdir_p(File.dirname(config_path))
31
49
  FileUtils.mkdir_p(path)
32
50
 
@@ -5,6 +5,6 @@
5
5
 
6
6
  module OpenVFS
7
7
  module Rb
8
- VERSION = "1.1.2"
8
+ VERSION = "1.2.0"
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openvfs-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Kidd