Exemplo n.º 1
0
  void receiveMessages() throws PersistenceException, EntityNotFoundExcepion {
    Identity identity = config.getSelectedIdentity();
    if (identity == null) {
      return;
    }
    java.util.List<DropMessage> dropMessages;
    try {
      dropMessages = httpDropConnector.receive(identity, lastDate);
    } catch (NullPointerException e) {
      return;
    }
    Contact sender = null;

    for (DropMessage d : dropMessages) {

      lastDate = config.getLastDropPoll(identity);
      if (lastDate.getTime() < d.getCreationDate().getTime()) {
        try {
          sender = contactRepository.findByKeyId(identity, d.getSenderKeyId());
        } catch (EntityNotFoundExcepion e) {
          logger.error(
              "Contact: with ID: " + d.getSenderKeyId() + " not found " + e.getMessage(), e);
          continue;
        }
        dropMessageRepository.addMessage(d, sender, identity, false);
        config.setLastDropPoll(identity, d.getCreationDate());
      }
    }
  }
  private void updateIdentity() {
    Identity identity = clientConfiguration.getSelectedIdentity();

    browseNav.setManaged(identity != null);
    contactsNav.setManaged(identity != null);
    syncNav.setManaged(identity != null);
    // inviteNav.setManaged(identity != null);
    selectedIdentity.setVisible(identity != null);
    // feebbackNav.setVisible(identity != null);

    avatarContainer.setVisible(identity != null);
    if (identity == null) {
      return;
    }

    final String currentAlias = identity.getAlias();
    if (currentAlias.equals(lastAlias)) {
      return;
    }

    new AvatarView(e -> currentAlias).getViewAsync(avatarContainer.getChildren()::setAll);
    alias.setText(currentAlias);
    lastAlias = currentAlias;

    if (clientConfiguration.getAccount() == null) {
      return;
    }
    mail.setText(clientConfiguration.getAccount().getUser());
  }
Exemplo n.º 3
0
 private ClientConfiguration getClientConfiguration(
     Persistence<String> persistence,
     IdentityRepository identityRepository,
     AccountRepository accountRepository) {
   ClientConfigurationRepository repo =
       new PersistenceClientConfigurationRepository(
           persistence, new ClientConfigurationFactory(), identityRepository, accountRepository);
   final ClientConfiguration config = repo.load();
   config.addObserver((o, arg) -> repo.save(config));
   return config;
 }
  @Override
  public void initialize(URL location, ResourceBundle resources) {
    this.resourceBundle = resources;

    navi.getChildren().clear();
    AccountingView accountingView = new AccountingView();
    actionlogView = new ActionlogView();
    accountingNav = createNavItem(resourceBundle.getString("layoutIdentity"), accountingView);
    navi.getChildren().add(accountingNav);

    browseNav = createNavItem(resourceBundle.getString("layoutBrowse"), new RemoteFSView());
    contactsNav = createNavItem(resourceBundle.getString("layoutContacts"), new ContactView());
    syncNav = createNavItem(resourceBundle.getString("layoutSync"), new SyncView());

    navi.getChildren().add(browseNav);
    navi.getChildren().add(contactsNav);
    navi.getChildren().add(syncNav);

    scrollContent.setFillWidth(true);

    if (clientConfiguration.getSelectedIdentity() == null) {
      accountingView.getView(scrollContent.getChildren()::setAll);
      setActiveNavItem(accountingNav);
    }

    updateIdentity();
    clientConfiguration.addObserver((o, arg) -> Platform.runLater(this::updateIdentity));

    uploadProgress.setProgress(0);
    uploadProgress.setDisable(true);

    WindowedTransactionGroup progress = new WindowedTransactionGroup();
    if (transferManager instanceof MonitoredTransferManager) {
      MonitoredTransferManager tm = (MonitoredTransferManager) transferManager;
      tm.onAdd(progress::add);
    }
    FxProgressModel progressModel = new FxProgressModel(progress);
    uploadProgress.progressProperty().bind(progressModel.progressProperty());
    progress.onProgress(
        () -> {
          if (progress.isEmpty()) {
            uploadProgress.setVisible(false);
          } else {
            uploadProgress.setVisible(true);
          }
        });

    createButtonGraphics();
  }
Exemplo n.º 5
0
  private ClientConfiguration initDiContainer() throws Exception {
    if (!Files.exists(DATABASE_FILE) && !Files.exists(DATABASE_FILE.getParent())) {
      Files.createDirectories(DATABASE_FILE.getParent());
    }

    Persistence<String> persistence =
        new SQLitePersistence(DATABASE_FILE.toFile().getAbsolutePath());
    transferManager = new MonitoredTransferManager(new DefaultTransferManager());
    customProperties.put("loadManager", transferManager);
    customProperties.put("transferManager", transferManager);
    customProperties.put("persistence", persistence);
    customProperties.put("dropUrlGenerator", new DropUrlGenerator("https://qdrop.prae.me"));
    identityRepository = new PersistenceIdentityRepository(persistence);
    customProperties.put("identityRepository", identityRepository);
    PersistenceAccountRepository accountRepository = new PersistenceAccountRepository(persistence);
    customProperties.put("accountRepository", accountRepository);
    contactRepository = new PersistenceContactRepository(persistence);
    customProperties.put("contactRepository", contactRepository);
    dropMessageRepository = new PersistenceDropMessageRepository(persistence);
    customProperties.put("dropMessageRepository", dropMessageRepository);
    customProperties.put("dropConnector", dropConnector);
    customProperties.put("reportHandler", new HockeyApp());
    ClientConfiguration clientConfig =
        getClientConfiguration(persistence, identityRepository, accountRepository);
    if (!clientConfig.hasDeviceId()) {
      clientConfig.setDeviceId(generateDeviceId());
    }
    PersistenceContactRepository contactRepository = new PersistenceContactRepository(persistence);
    customProperties.put("contactRepository", contactRepository);
    customProperties.put("clientConfiguration", clientConfig);
    customProperties.put("primaryStage", primaryStage);

    rendererFactory.setFallbackRenderer(new PlaintextMessageRenderer());
    customProperties.put("messageRendererFactory", rendererFactory);

    Injector.setConfigurationSource(customProperties::get);
    Injector.setInstanceSupplier(new RecursiveInjectionInstanceSupplier(customProperties));
    return clientConfig;
  }
Exemplo n.º 6
0
 private void addShareMessageRenderer(Identity arg) {
   executorService.submit(
       () -> {
         ShareNotificationRenderer renderer =
             new ShareNotificationRenderer(
                 ((BoxVolumeFactory) customProperties.get("boxVolumeFactory"))
                     .getVolume(config.getAccount(), arg)
                     .getReadBackend(),
                 sharingService);
         rendererFactory.addRenderer(
             DropMessageRepository.PAYLOAD_TYPE_SHARE_NOTIFICATION, renderer);
       });
 }
Exemplo n.º 7
0
  @Override
  public void start(Stage stage) throws Exception {
    primaryStage = stage;
    setUserAgentStylesheet(STYLESHEET_MODENA);

    config = initDiContainer();

    SceneAntialiasing aa = SceneAntialiasing.BALANCED;
    primaryStage
        .getIcons()
        .setAll(
            new javafx.scene.image.Image(getClass().getResourceAsStream("/logo-invert_small.png")));
    Scene scene;

    Platform.setImplicitExit(false);
    primaryStage.setTitle(TITLE);
    scene = new Scene(new LoginView().getView(), 370, 550, true, aa);
    primaryStage.setScene(scene);

    config.addObserver(
        (o, arg) -> {
          Platform.runLater(
              () -> {
                if (arg instanceof Account) {
                  try {
                    ClientConfiguration configuration =
                        (ClientConfiguration) customProperties.get("clientConfiguration");
                    Account acc = (Account) arg;
                    AccountingServer server =
                        new AccountingServer(
                            new URI(acc.getProvider()), acc.getUser(), acc.getAuth());
                    AccountingHTTP accountingHTTP =
                        new AccountingHTTP(server, new AccountingProfile());

                    BoxVolumeFactory factory =
                        new BlockBoxVolumeFactory(
                            configuration.getDeviceId().getBytes(),
                            accountingHTTP,
                            identityRepository);
                    boxVolumeFactory = new CachedBoxVolumeFactory(factory);
                    customProperties.put("boxVolumeFactory", boxVolumeFactory);
                    sharingService = new BlockSharingService(dropMessageRepository, dropConnector);
                    customProperties.put("sharingService", sharingService);

                    new Thread(getSyncDaemon(config)).start();
                    new Thread(getDropDaemon(config)).start();
                    view = new LayoutView();
                    Parent view = this.view.getView();
                    Scene layoutScene = new Scene(view, 800, 600, true, aa);
                    Platform.runLater(() -> primaryStage.setScene(layoutScene));

                    if (config.getSelectedIdentity() != null) {
                      addShareMessageRenderer(config.getSelectedIdentity());
                    }
                  } catch (Exception e) {
                    logger.error("failed to init background services: " + e.getMessage(), e);
                    // TODO to something with the fault
                  }
                } else if (arg instanceof Identity) {
                  addShareMessageRenderer((Identity) arg);
                }
              });
        });

    dropMessageRepository.addObserver(new ShareNotificationHandler(config));

    setTrayIcon(primaryStage);

    Runtime.getRuntime()
        .addShutdownHook(
            new Thread() {
              public void run() {
                Platform.exit();
              }
            });
    primaryStage.show();
  }
Exemplo n.º 8
0
 protected SyncDaemon getSyncDaemon(ClientConfiguration config) {
   new Thread(transferManager, "TransactionManager").start();
   return new SyncDaemon(
       config.getBoxSyncConfigs(), new DefaultSyncerFactory(boxVolumeFactory, transferManager));
 }