source: trunk/third/nautilus-cd-burner/list_cddrives.c @ 21565

Revision 21565, 3.9 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r21564, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2/*
3 * Copyright (C) 2003-2004 Bastien Nocera <hadess@hadess.net>
4 *
5 * cd-recorder.c
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 *
21 * Authors: Bastien Nocera <hadess@hadess.net>
22 */
23
24#include <glib.h>
25#include <string.h>
26#include "cd-drive.h"
27
28static char*
29add_desc (char *string, const char *addition)
30{
31        char *new;
32
33        if (strcmp (string, "") == 0) {
34                new = g_strdup_printf ("%s", addition);
35        } else {
36                new = g_strdup_printf ("%s/%s", string, addition);
37        }
38        g_free (string);
39        return new;
40}
41
42static char*
43drive_type (int type)
44{
45        char *string;
46
47        string = g_strdup ("");
48        if (type & CDDRIVE_TYPE_FILE) {
49                string = add_desc (string, "File");
50        }
51        if (type & CDDRIVE_TYPE_CD_RECORDER) {
52                string = add_desc (string, "CD Recorder");
53        }
54        if (type & CDDRIVE_TYPE_DVD_RAM_RECORDER) {
55                string = add_desc (string, "DVD-RAM");
56        }
57        if (type & CDDRIVE_TYPE_DVD_RW_RECORDER) {
58                string = add_desc (string, "DVD-RW");
59        }
60        if (type & CDDRIVE_TYPE_DVD_PLUS_R_RECORDER) {
61                string = add_desc (string, "DVD+R");
62        }
63        if (type & CDDRIVE_TYPE_DVD_PLUS_RW_RECORDER) {
64                string = add_desc (string, "DVD+RW");
65        }
66        if (type & CDDRIVE_TYPE_CD_DRIVE) {
67                string = add_desc (string, "CD Drive");
68        }
69        if (type & CDDRIVE_TYPE_DVD_DRIVE) {
70                string = add_desc (string, "DVD Drive");
71        }
72
73        return string;
74}
75
76static const char*
77media_type_get_string (int type)
78{
79        switch (type) {
80        case CD_MEDIA_TYPE_BUSY:
81                return "Unknown media, CD drive is busy";
82        case CD_MEDIA_TYPE_ERROR:
83                return "Couldn't open media";
84        case CD_MEDIA_TYPE_UNKNOWN:
85                return "Unknown Media";
86        case CD_MEDIA_TYPE_CD:
87                return "Commercial CD or Audio CD";
88        case CD_MEDIA_TYPE_CDR:
89                return "CD-R";
90        case CD_MEDIA_TYPE_CDRW:
91                return "CD-RW";
92        case CD_MEDIA_TYPE_DVD:
93                return "DVD";
94        case CD_MEDIA_TYPE_DVDR:
95                return "DVD-R, or DVD-RAM";
96        case CD_MEDIA_TYPE_DVDRW:
97                return "DVD-RW";
98        case CD_MEDIA_TYPE_DVD_RAM:
99                return "DVD-RAM";
100        case CD_MEDIA_TYPE_DVD_PLUS_R:
101                return "DVD+R";
102        case CD_MEDIA_TYPE_DVD_PLUS_RW:
103                return "DVD+RW";
104        }
105
106        return "Broken media type";
107}
108
109static void
110list_cdroms (void)
111{
112        GList *cdroms, *l;
113        CDDrive *cd;
114
115        cdroms = scan_for_cdroms (FALSE, FALSE);
116
117        for (l = cdroms; l != NULL; l = l->next)
118        {
119                char *type_str;
120                const char *media;
121                int media_type;
122                gboolean is_rewritable;
123                gint64 size;
124
125                cd = l->data;
126                type_str = drive_type (cd->type);
127                media_type = cd_drive_get_media_type_and_rewritable (cd, &is_rewritable);
128                media = media_type_get_string (media_type);
129
130                g_print ("name: %s device: %s max_speed_read: %d\n",
131                                cd->display_name, cd->device,
132                                cd->max_speed_read);
133                g_print ("type: %s\n", type_str);
134                g_print ("media type: %s%s\n", media, is_rewritable?" (rewritable)":"");
135                size = cd_drive_get_media_size (cd);
136                g_print ("media size: %0.2f megs", (float) size / 1024 / 1024);
137                if (media_type == CD_MEDIA_TYPE_CDR || media_type == CD_MEDIA_TYPE_CDRW) {
138                        g_print ("approx. or %d mins %d secs)\n", SIZE_TO_TIME(size) / 60, SIZE_TO_TIME(size) % 60);
139                } else {
140                        g_print ("\n");
141                }
142                g_print ("CD-Recorder/SCSI devices only: max_speed_write: %d"
143                                " id: %s\n", cd->max_speed_write,
144                                cd->cdrecord_id);
145                g_print ("\n");
146                g_free (type_str);
147                cd_drive_free (cd);
148        }
149        g_list_free (cdroms);
150}
151
152int main (int argc, char **argv)
153{
154        list_cdroms ();
155
156        return 0;
157}
158
Note: See TracBrowser for help on using the repository browser.