Beispiel #1
0
int draw_sidebar(int menu) {
    BUFFY *tmp;

#ifndef USE_SLANG_CURSES
    attr_t attrs;
#endif /* ifndef USE_SLANG_CURSES */
    short delim_len = strlen(SidebarDelim);
    short color_pair;

    static bool initialized = false;
    static int prev_show_value;
    static short saveSidebarWidth;
    int lines = 0;
    int SidebarHeight;

    if (globals.has_option(OPTSTATUSONTOP) || globals.has_option(OPTHELP))
        lines++;  /* either one will occupy the first line */

    /* initialize first time */
    if (!initialized) {
        prev_show_value = globals.has_option(OPTSIDEBAR);
        saveSidebarWidth = SidebarWidth;

        if (!globals.has_option(OPTSIDEBAR)) SidebarWidth = 0;
        initialized = true;
    }

    /* save or restore the value SidebarWidth */
    if (prev_show_value != globals.has_option(OPTSIDEBAR)) {
        if (prev_show_value
            && !globals.has_option(OPTSIDEBAR)) {
            saveSidebarWidth = SidebarWidth;
            SidebarWidth = 0;
        } else if (!prev_show_value && globals.has_option(OPTSIDEBAR)) {
            mutt_buffy_check(1); /* we probably have bad or no numbers */
            SidebarWidth = saveSidebarWidth;
        }
        prev_show_value = globals.has_option(OPTSIDEBAR);
    }


    /*	if ( SidebarWidth == 0 ) return 0; */
    if ((SidebarWidth > 0)
        && globals.has_option(OPTSIDEBAR)
        && (delim_len >= SidebarWidth)) {
        globals.unset_option(OPTSIDEBAR);

        /* saveSidebarWidth = SidebarWidth; */
        if (saveSidebarWidth > delim_len) {
            SidebarWidth = saveSidebarWidth;
            mutt_error(_(
                           "Value for sidebar_delim is too long. Disabling sidebar."));
            sleep(2);
        } else {
            SidebarWidth = 0;
            mutt_error(_(
                           "Value for sidebar_delim is too long. Disabling sidebar. Please set your sidebar_width to a sane value."));
            sleep(4); /* the advise to set a sane value should be seen long
                         enough */
        }
        saveSidebarWidth = 0;
        return 0;
    }

    if ((SidebarWidth == 0) || !globals.has_option(OPTSIDEBAR)) {
        if (SidebarWidth > 0) {
            saveSidebarWidth = SidebarWidth;
            SidebarWidth = 0;
        }
        globals.unset_option(OPTSIDEBAR);
        return 0;
    }

    /* get attributes for divider */
    SETCOLOR(MT_COLOR_STATUS);
#ifndef USE_SLANG_CURSES
    attr_get(&attrs, &color_pair, 0);
#else /* ifndef USE_SLANG_CURSES */
    color_pair = attr_get();
#endif /* ifndef USE_SLANG_CURSES */
    SETCOLOR(MT_COLOR_NORMAL);

    /* draw the divider */

    SidebarHeight =  LINES - 1;

    if (globals.has_option(OPTHELP) || !globals.has_option(OPTSTATUSONTOP))
        SidebarHeight--;

    for (; lines < SidebarHeight; lines++) {
        move(lines, SidebarWidth - delim_len);
        addstr(NONULL(SidebarDelim));
#ifndef USE_SLANG_CURSES
        mvchgat(lines, SidebarWidth - delim_len, delim_len, 0, color_pair,
                NULL);
#endif /* ifndef USE_SLANG_CURSES */
    }

    if (Incoming == 0) return 0;

    lines = 0;

    if (globals.has_option(OPTSTATUSONTOP) || globals.has_option(OPTHELP))
        lines++;  /* either one will occupy the first line */

    if ((known_lines != LINES) || (TopBuffy == 0) || (BottomBuffy == 0))
        calc_boundaries(menu);

    if (CurBuffy == 0) CurBuffy = Incoming;

    tmp = TopBuffy;

    SETCOLOR(MT_COLOR_NORMAL);

    for (; tmp
         && lines < SidebarHeight; tmp = tmp->next) {
        if (tmp == CurBuffy)
            SETCOLOR(MT_COLOR_INDICATOR);
        else if (tmp->msg_unread > 0)
            SETCOLOR(MT_COLOR_NEW);
        else if (tmp->msg_flagged > 0)
            SETCOLOR(MT_COLOR_FLAGGED);
        else
            SETCOLOR(MT_COLOR_NORMAL);

        move(lines, 0);

        if (Context
            && (!strcmp(tmp->path, Context->path)
                || !strcmp(tmp->realpath, Context->path))) {
            tmp->msg_unread = Context->unread;
            tmp->msgcount = Context->msgcount;
            tmp->msg_flagged = Context->flagged;
        }

        /* check whether Maildir is a prefix of the current folder's path */
        short maildir_is_prefix = 0;

        if ((strlen(tmp->path) > strlen(Maildir))
            && (strncmp(Maildir, tmp->path, strlen(Maildir)) == 0))
            maildir_is_prefix = 1;

        /* calculate depth of current folder and generate its display name with indented spaces */
        int sidebar_folder_depth = 0;
        char *sidebar_folder_name =
            globals.has_option(OPTSIDEBARSHORTPATH) ? (char *) mutt_basename(tmp->path)
                                        : (char *)(tmp->path + maildir_is_prefix * (strlen(Maildir) + 1));

        if (maildir_is_prefix
            && globals.has_option(OPTSIDEBARFOLDERINDENT)) {
            char *tmp_folder_name;
            int i;
            tmp_folder_name = tmp->path + strlen(Maildir) + 1;

            for (i = 0; i < strlen(tmp->path) - strlen(Maildir); i++) {
                if ((tmp_folder_name[i] == '/')
                    || (tmp_folder_name[i] == '.')) sidebar_folder_depth++;
            }

            if (sidebar_folder_depth > 0) {
                if (globals.has_option(OPTSIDEBARSHORTPATH)) {
                    tmp_folder_name = strrchr(tmp->path, '.');

                    if (tmp_folder_name == NULL)
                        tmp_folder_name = (__typeof__(tmp_folder_name)) mutt_basename(tmp->path);
                    else
                        tmp_folder_name++;
                } else
                    tmp_folder_name = tmp->path + strlen(Maildir) + 1;
                sidebar_folder_name = (__typeof__(sidebar_folder_name))
                    malloc(strlen(tmp_folder_name) + sidebar_folder_depth * strlen(NONULL(SidebarIndentStr)) + 1);
                sidebar_folder_name[0] = 0;

                for (i = 0; i < sidebar_folder_depth; i++)
                    strncat(sidebar_folder_name, NONULL(
                                SidebarIndentStr),
                            strlen(NONULL(SidebarIndentStr)));
                strncat(sidebar_folder_name, tmp_folder_name,
                        strlen(tmp_folder_name));
            }
        }
        printw("%.*s", SidebarWidth - delim_len + 1,
               make_sidebar_entry(sidebar_folder_name, tmp->msgcount,
                                  tmp->msg_unread, tmp->msg_flagged));

        if (sidebar_folder_depth > 0)
            free(sidebar_folder_name);
        lines++;
    }
    SETCOLOR(MT_COLOR_NORMAL);

    for (; lines < SidebarHeight; lines++) {
        int i = 0;
        move(lines, 0);

        for (; i < SidebarWidth - delim_len; i++)
            addch(' ');
    }
    return 0;
}
Beispiel #2
0
/* return 0 on success, -1 on abort, 1 on error */
int mutt_check_overwrite (const char *attname, const char *path,
                          char *fname, size_t flen, int *append,
                          char **directory)
{
  int rc = 0;
  char tmp[_POSIX_PATH_MAX];
  struct stat st;

  strfcpy (fname, path, flen);
  if (access (fname, F_OK) != 0)
    return 0;
  if (stat (fname, &st) != 0)
    return -1;
  if (S_ISDIR (st.st_mode)) {
    if (directory) {
      switch (mutt_multi_choice
              (_("File is a directory, save under it? [(y)es, (n)o, (a)ll]"),
               _("yna"))) {
      case 3:                  /* all */
        str_replace (directory, fname);
        break;
      case 1:                  /* yes */
        mem_free (directory);
        break;
      case -1:                 /* abort */
        mem_free (directory);
        return -1;
      case 2:                  /* no */
        mem_free (directory);
        return 1;
      }
    }
    else
      if ((rc =
           mutt_yesorno (_("File is a directory, save under it?"),
                         M_YES)) != M_YES)
      return (rc == M_NO) ? 1 : -1;

    if (!attname || !attname[0]) {
      tmp[0] = 0;
      if (mutt_get_field (_("File under directory: "), tmp, sizeof (tmp),
                          M_FILE | M_CLEAR) != 0 || !tmp[0])
        return (-1);
      mutt_concat_path (fname, path, tmp, flen);
    }
    else
      mutt_concat_path (fname, path, mutt_basename (attname), flen);
  }

  if (*append == 0 && access (fname, F_OK) == 0) {
    switch (mutt_multi_choice
            (_("File exists, (o)verwrite, (a)ppend, or (c)ancel?"), _("oac")))
    {
    case -1:                   /* abort */
      return -1;
    case 3:                    /* cancel */
      return 1;

    case 2:                    /* append */
      *append = M_SAVE_APPEND;
      break;
    case 1:                    /* overwrite */
      *append = M_SAVE_OVERWRITE;
      break;
    }
  }
  return 0;
}