GetPixbufForFile() public static method

public static GetPixbufForFile ( string filename ) : Gdk.Pixbuf
filename string
return Gdk.Pixbuf
Exemplo n.º 1
0
        protected void OnButtonScanClicked(object sender, EventArgs e)
        {
            GetFromScanner scanWin = new GetFromScanner();

            scanWin.Show();
            int result = scanWin.Run();

            if (result == (int)ResponseType.Ok)
            {
                FilesStore.AppendValues(-1,
                                        scanWin.FileName,
                                        scanWin.File.LongLength,
                                        FileIconWorks.GetPixbufForFile(scanWin.FileName),
                                        scanWin.File
                                        );
            }
            scanWin.Destroy();
        }
Exemplo n.º 2
0
        protected void OnButtonAddClicked(object sender, EventArgs e)
        {
            FileChooserDialog Chooser = new FileChooserDialog("Выберите файл для прикрепления...",
                                                              (Gtk.Window) this.Toplevel,
                                                              FileChooserAction.Open,
                                                              "Отмена", ResponseType.Cancel,
                                                              "Прикрепить", ResponseType.Accept);

            if ((ResponseType)Chooser.Run() == ResponseType.Accept)
            {
                Chooser.Hide();
                logger.Info("Чтение файла...");

                byte[] file;
                using (FileStream fs = new FileStream(Chooser.Filename, FileMode.Open, FileAccess.Read)) {
                    using (MemoryStream ms = new MemoryStream()) {
                        fs.CopyTo(ms);
                        file = ms.ToArray();
                    }
                }
                string fileName = System.IO.Path.GetFileName(Chooser.Filename);
                //При необходимости обрезаем имя файла.
                if (fileName.Length > MaxFileNameLength)
                {
                    string ext  = System.IO.Path.GetExtension(fileName);
                    string name = System.IO.Path.GetFileNameWithoutExtension(fileName);
                    fileName = String.Format("{0}{1}",
                                             name.Remove((int)MaxFileNameLength - ext.Length),
                                             ext);
                }

                FilesStore.AppendValues(-1,
                                        fileName,
                                        file.LongLength,
                                        FileIconWorks.GetPixbufForFile(Chooser.Filename),
                                        file
                                        );
                logger.Info("Ok");
            }
            Chooser.Destroy();
        }
Exemplo n.º 3
0
        public void UpdateFileList(bool copy = false)
        {
            if (TableName == "" || AttachToTable == "" || ItemId < 0)
            {
                return;
            }
            logger.Info("Загружаем список файлов для {0}<{1}>", AttachToTable, ItemId);
            string filefield = copy ? ", file " : "";
            string sql       = String.Format("SELECT id, name, size{1} FROM {0} WHERE item_group = @item_group AND item_id = @item_id",
                                             TableName, filefield);

            try {
                MySqlCommand cmd = new MySqlCommand(sql, (MySqlConnection)QSMain.ConnectionDB);
                cmd.Parameters.AddWithValue("@item_group", AttachToTable);
                cmd.Parameters.AddWithValue("@item_id", ItemId);
                FilesStore.Clear();
                byte[] file = null;
                using (MySqlDataReader rdr = cmd.ExecuteReader()) {
                    while (rdr.Read())
                    {
                        if (copy)
                        {
                            file = new byte[rdr.GetInt64("size")];
                            rdr.GetBytes(rdr.GetOrdinal("file"), 0, file, 0, rdr.GetInt32("size"));
                        }
                        FilesStore.AppendValues(copy ? -1 : rdr.GetInt32("id"),
                                                rdr.GetString("name"),
                                                rdr.GetInt64("size"),
                                                FileIconWorks.GetPixbufForFile(rdr.GetString("name")),
                                                copy ? file : null
                                                );
                    }
                }
                logger.Info("Ок");
            } catch (Exception ex) {
                string mes = "Ошибка списка файлов!";
                logger.Error(ex, mes);
                throw new ApplicationException(mes, ex);
            }
        }