Exemple #1
0
void on_button_url_clicked(GtkButton * button, gpointer user_data)
{
  TinySpawn spawn ("curl");
  spawn.arg ("-sS"); // Make curl silent, but show errors.
  string url = gtk_entry_get_text (GTK_ENTRY (entry_url));
  url.append ("/ipc/setmessage.php");
  spawn.arg (url);
  spawn.read ();
  spawn.run ();
  string message;
  for (unsigned int i = 0; i < spawn.standardout.size(); i++) {
    message.append (spawn.standardout[i] + "\n");
  }
  for (unsigned int i = 0; i < spawn.standarderr.size(); i++) {
    message.append (spawn.standarderr[i] + "\n");
  }
  if (message.empty()) {
    if (spawn.exitstatus == 0) {
      message = "Access okay";
    }
  }
  gtk_label_set_text (GTK_LABEL (label_url), message.c_str());
}
bool on_timeout (gpointer data)
{
  if (folders.empty()) {
    message ("");
    message (_("Ready."));
    message (_("You can close the window, or it will close itself in 5 minutes."));
    g_timeout_add (300000, GSourceFunc(exit_timeout), NULL);
  } else {
    string folder = folders[0];
    folders.pop_front ();

    // Keep going round and round in circles ...
    folders.push_back(folder);

    if (folder.empty() ) {
      if (we_loop) {
        message (_("Will send and receive again after 5 minutes."));
        message (_("Or close the window to not send and receive again."));
        g_timeout_add(300000, GSourceFunc(on_timeout), NULL);
      } else {
      message (_("Finished"));
      message (_("You can close the window, or it will close itself in 5 minutes."));
        g_timeout_add (300000, GSourceFunc(exit_timeout), NULL);
      }

    } else { 

      message (folder);

      // Tell git about the default method for pushing.
      {
        TinySpawn spawn ("git");
        spawn.arg ("config");
        spawn.arg ("push.default");
        spawn.arg ("matching");
        spawn.workingdirectory (folder);
        spawn.run ();
      }
    
      // Add everything because things could have been added or changed.
      {
        TinySpawn spawn ("git");
        spawn.arg ("add");
        spawn.arg (".");
        spawn.workingdirectory (folder);
        spawn.run ();
      }
    
      // Show status.
      {
        TinySpawn spawn ("git");
        spawn.arg ("status");
        spawn.workingdirectory (folder);
        spawn.read ();
        spawn.run ();
        for (unsigned int i = 0; i < spawn.standardout.size(); i++) {
          message (spawn.standardout[i]);
        }
        for (unsigned int i = 0; i < spawn.standarderr.size(); i++) {
          message (spawn.standarderr[i]);
        }
      }
    
      // Commit changes locally.
      {
        TinySpawn spawn ("git");
        spawn.arg ("commit");
        spawn.arg ("-a");
        spawn.arg ("-m");
        spawn.arg ("Send and receive");
        spawn.workingdirectory (folder);
        spawn.read ();
        spawn.run ();
        for (unsigned int i = 0; i < spawn.standardout.size(); i++) {
          message (spawn.standardout[i]);
        }
        for (unsigned int i = 0; i < spawn.standarderr.size(); i++) {
          message (spawn.standarderr[i]);
        }
      }
    
      // Pull changes from the remote repository.
      {
        TinySpawn spawn ("git");
        spawn.arg ("pull");
        spawn.workingdirectory (folder);
        spawn.read ();
        spawn.run ();
        // Normal operation: Exit status = 0.
        // Merge conflict: Exit status = 256.
        // Remote repository unavailable: Exit status = 256.
        // Conclusion: The exit status cannot be used conclusively for finding out about a merge conflict.
        bool merge_conflict = false;
        for (unsigned int i = 0; i < spawn.standardout.size(); i++) {
          if (spawn.standardout[i].find ("CONFLICT") != string::npos) {
            merge_conflict = true;
          }
          message (spawn.standardout[i]);
        }
        for (unsigned int i = 0; i < spawn.standarderr.size(); i++) {
          message (spawn.standarderr[i]);
        }
        if (merge_conflict) {
          message (_("Bibledit will resolve conflicts between its own data and the data on the server."));
          // Resolve merge conflict.
          TinySpawn mergetool ("php");
          string script;
          gchar *name;
          name = g_build_filename (PACKAGE_DATA_DIR, "conflictcli.php", NULL);
          script = name;
          g_free(name);
          mergetool.arg (script);
          mergetool.arg (folder);
          mergetool.read ();
          mergetool.run ();
          for (unsigned int i = 0; i < mergetool.standardout.size(); i++) {
            message (mergetool.standardout[i]);
          }
          for (unsigned int i = 0; i < mergetool.standarderr.size(); i++) {
            message (mergetool.standarderr[i]);
          }
        }
      }
    
      // Push changes to the remote repository.
      {
        TinySpawn spawn ("git");
        spawn.arg ("push");
        spawn.workingdirectory (folder);
        spawn.read ();
        spawn.run ();
        for (unsigned int i = 0; i < spawn.standardout.size(); i++) {
          message (spawn.standardout[i]);
        }
        for (unsigned int i = 0; i < spawn.standarderr.size(); i++) {
          message (spawn.standarderr[i]);
        }
      }
  
      // Next folder.
      g_timeout_add(500, GSourceFunc(on_timeout), NULL);
    
    }

  }

  return false;
}